嵌套类,体系结构x86_64的未定义符号

时间:2014-01-11 13:28:17

标签: c++ inner-classes

我计划使用C ++实现一个带有嵌套类的列表,如下所示:

class List{
  private:
    class ListItem{
        public:
            ListItem(int val, ListItem* next): _val(val), _next(next){}
            ListItem(int val): _val(val), _next(0){}
            int _val;
            ListItem* _next;
    };

    ListItem* _head;
  public:
    List():_head(0){}
    void add( int );
    void print();
};

void List::add(int val){
    _head = new ListItem(val, _head);
}

void List::print(){
    ListItem* tmp = _head;
    while( tmp ){
        cout<< tmp->_val<< " ";
        tmp = tmp->_next;
    }
    cout<<endl;
}

错误:

Undefined symbols for architecture x86_64:
  "List::add(int)", referenced from:
      _main in ccNeyQRz.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

0 个答案:

没有答案