c++ - conversion operator with forward declartation -


i'm trying work conversion operators in c++ have 2 classes i'm trying convert 1 other, , getting errors:

class cow; //error: forward declaration of 'struct cow'  class horse { public:     horse():i(0){}     horse(int i):i(i){}     operator cow() const { return cow(i); } // error: invalid use of incomplete type 'struct cow'                                             //error : return type 'struct cow' incomplete  private:     int i; };  class cow{ public:     cow():i(0){}     cow(int i):i(i){}     operator horse() const { return horse(i); } private:     int i; }; 

can tell me i'm doing wrong?

try this:

class cow;  class horse { public:     horse():i(0){}     horse(int i):i(i){}     operator cow() const;                      private:     int i; };  class cow{ public:     cow():i(0){}     cow(int i):i(i){}     operator horse() const; private:     int i; };  horse::operator cow() const { return cow(i); }                                       cow::operator horse() const { return horse(i); } 

Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

How to get multiresult with multicondition in Sql Server -