From: Carlo W. <ca...@al...> - 2004-09-30 12:24:40
|
On Thu, Sep 30, 2004 at 04:54:59AM -0700, Vivek Jishtu wrote: > This is just a sample code that compiles using the > Microsoft C++ compiler but seems to be giving problems > when compiled in Dev-C++. The problem is that I am > trying to port a library to Mingw but this kind of > functionality has been used in the library and I am > getting all sorts or wierd errors because of this. > > What am I missing out? It would help if you showed the errors. > Regards, > Vivek Jishtu > > ------------------------------------------------ > > #include <iostream> > > class First{ > > public: > void SomeWork() > { > std::cout <<"Inside SomeWork"; > } > }; > > class Second > { > > public: > void myfun(First &obj) > { > obj.SomeWork(); > } > }; > > int main() > { > Second Obj2; > Obj2.myfun(First()); I don't think it is allowed to pass a temporary to a function taking a non-const reference. > return 0; > } Try using #include <iostream> class First{ public: void SomeWork() const { std::cout <<"Inside SomeWork"; } }; class Second { public: void myfun(First const& obj) { obj.SomeWork(); } }; int main() { Second Obj2; Obj2.myfun(First()); return 0; } -- Carlo Wood <ca...@al...> |