我的静态topStock方法有什么问题?它引用了股票和股票t.它不应该返回s或t的副本吗?
错误:'.'之前的预期primary-expression 令牌|
#include <iostream>
using namespace std;
class Stock {
public:
Stock() : x(0){ }
Stock(int val) : x(val){}
void display() const;
static Stock topStock(const Stock& s, const Stock& t) {
if (s.x > t.x)
return s;
else
return t;
}
int x;
};
void Stock::display() const
{
std::cout << this->x;
}
int main()
{
Stock s(9);
Stock y(8);
Stock z = Stock.topStock(s, y);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
更改
Stock.topStock(s, y);
Run Code Online (Sandbox Code Playgroud)
至
Stock::topStock(s, y);
Run Code Online (Sandbox Code Playgroud)
因为它是一个静态成员函数.
| 归档时间: |
|
| 查看次数: |
57 次 |
| 最近记录: |