头文件中定义的函数的原型错误

时间:2015-02-21 15:00:57

标签: c++ overloading

我来到了这个奇怪的error : prototype for ‘void Table::add(E)’ does not match any in class ‘Table’。我知道这个错误是当函数没有在类体中定义或者用错误的参数或返回类型定义时,但这不是我的情况。

add函数在头文件中定义。奇怪的是,当我评论其他功能(删除,打印)时,gcc并没有抱怨它。 这是我的代码:

table.hpp

class Table {
    private:

    public:
    Table(int size=100);
    Table(Table& t);
    ~Table();

    void print();
    void add(string name, string num);
    void add(E e);
    void remove(string name, string num);
    string to_string();

    /* some function definitions and operators */
};

table.cpp

void Table::add(E e){
    if (size == nb_elem)
        cout << "Error";
    else
        t[nb_elem++] = e;
}

void Table::add(string name, string num) {
    E e(name, num);
    this->add(e); //this->add(E(name, num);
}

注意

我是一门学习C ++的语言。

1 个答案:

答案 0 :(得分:0)

查看项目文件时,我找到了一个文件table.hpp.ghc,问题与此one完全相同。我通过删除此文件解决了我的问题。

我不知道为什么gcc会创建它。

相关问题