静态成员函数错误;如何正确写签名? [英] Static member functions error; How to properly write the signature?

查看:151
本文介绍了静态成员函数错误;如何正确写签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am getting an error when trying to compile my code in g++ using the current signature:

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

我的问题有两个:


  1. 为什么不以这种方式编译?

  2. 正确的签名,以及为什么?

签名在使用C ++时一直是我的死亡

Signatures have always been the death of me when using C++

Edit:下面是类头文件:

Here is the class header file, as well:

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);


推荐答案

我猜你做过类似的事情:

I'm guessing you've done something like:

class Foo
{
    static void Bar();
};

...

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

这不正确。您不需要第二个 static

This is incorrect. You don't need the second "static".

这篇关于静态成员函数错误;如何正确写签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆