168

尝试使用当前签名在 g++ 中编译我的代码时出现错误:

cannot declare member function static void Foo::Bar(std::ostream&, const Foo::Node*) to have static linkage

我的问题是双重的:

  1. 为什么它不以这种方式编译?
  2. 什么是正确的签名,为什么?

使用 C++ 时,签名一直是我的死因

编辑:这里也是类头文件:

class Foo {


public:
    Foo();

    ~Foo();

    bool insert(const Foo2 &v);

    Foo * find(const Foo2 &v);

    const Foo * find(const Foo2 &v) const;

    void output(ostream &s) const;

private:
    //Foo(const Foo &v);
    //Foo& operator =(const Foo &v);
    //Not implemented; unneeded


    struct Node {
        Foo2 info;
        Node *left;
        Node *right;
    };

    Node * root;

    static bool insert(const Foo2 &v, Node *&p);


    static void output(ostream &s, const Node *p);


    static void deleteAll(Node *p);
4

1 回答 1

420

我猜你做过类似的事情:

class Foo
{
    static void Bar();
};

...

static void Foo::Bar()
{
    ...
}

static void Foo::Bar”不正确。你不需要第二个“ static”。

于 2011-11-15T00:26:48.513 回答