compile error C2555
От: samarityanin  
Дата: 21.11.03 15:16
Оценка:
Подскажите, как исправить:

class A {
public:
    virtual void get()  = 0;
};

class A_int : public A {
   int i;
public:
   A_int(int v) : a(v) {}
   virtual int get() {return i;} // error C2555
};

class A_str : public A {
   string str;
public:
   A_str(const string& v) : str(v) {}
   virtual str& get() {return str;}  // error C2555
};

void main()
{
   list<A*> lst;

   lst.push_back(new A_int(1));
   lst.push_back(new A_str("something"));

   int s;
   for(list<A*>::iterator it = lst.begin(); it != lst.end(); it++)
   {
       if(dynamic_cast<A_int*>(*it) != 0)
          s += (*it)->get();
   }
}

(в общем, нужна подобная конструкция)
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.