尝试使用当前签名在 g++ 中编译我的代码时出现错误:
cannot declare member function static void Foo::Bar(std::ostream&, const Foo::Node*) to have static linkage
我的问题有两个:
- 为什么不这样编译?
- 什么是正确的签名,为什么?
签名一直是我在使用 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);
最佳答案
我猜你做过类似的事情:
class Foo
{
static void Bar();
};
...
static void Foo::Bar()
{
...
}
“static void Foo::Bar
”不正确。您不需要第二个“static
”。
关于c++ - 静态成员函数错误;如何正确书写签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8130066/