如何从静态成员函数返回副本?

run*_*431 0 c++

我的静态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)

0x4*_*2D2 6

更改

Stock.topStock(s, y);
Run Code Online (Sandbox Code Playgroud)

至

Stock::topStock(s, y);
Run Code Online (Sandbox Code Playgroud)

因为它是一个静态成员函数.