Re: [Dev-C++] classes and references
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Goran K. <go...@re...> - 2003-05-03 22:52:55
|
> So why the hell doesn't it make a reference from it then???
>=20
try defining your return type as a reference with a simple and(&) after t=
he class name.
myclass& make_myclass(void)
{
myclass mc_tmp;
return mc_tmp;
}
regards,
goran
V ned, 04.05.2003 ob 00:17, je OROSZI Bal=E1zs poslal(a):
> Hi!
>=20
> Please, C++ gurus out there - help me, I think I'm gonna get crazy soon.
>=20
> Finally I have decided to learn C++. 400 pages so far from Bjarne's=20
> book. I can tell - it is a whole bunch of crap. I'm sure Bjarne can=20
> desing C++ programs very well, but he cannot design a book, that's sure=
.=20
> You just cannot find the thing that you need at the right place, it is=20
> spread across 1600 pages. Find it - well thanks a lot :)
>=20
> So, to the point. I have a question about a thing, that works with=20
> Borland, and MSVC, but not with g++. Here it is:
>=20
> I have a class, name it "myclass".
> I have a function, which return "myclass".
> I have a function, which uses "myclass".
> Here they are:
>=20
> //The class
> class myclass{
> public:
> static void use_myclass(myclass& mc){ //The using function
> printf("Value: %d\n",mc.value);
> }
> int value;
> };
>=20
> //The returner function
> myclass make_myclass(void)
> {
> myclass mc_tmp;
> return mc_tmp;
> }
>=20
> And so why the hell doesn't this work?:
>=20
> int main()
> {
> myclass::use_myclass(make_myclass());
> return 0;
> }
>=20
> WHILE THIS DOES:
>=20
> int main()
> {
> myclass mc_tmp =3D make_myclass();
> myclass::use_myclass(mc_tmp);
> return 0;
> }
>=20
> The ONLY difference is, that I put the result in a temporary variable,=20
> then I used that.
> The compiler gave this warning to the first one:
>=20
> test.cpp:19: no matching function for call to=20
> `myclass::use_myclass(myclass)'
> test.cpp:5: candidates are: static void myclass::use_myclass(myclass&)
>=20
> So why the hell doesn't it make a reference from it then???
>=20
> Please help me with this, I am at the bounds of getting crazy... really=
!
>=20
> Thank you!
>=20
> --
> Greetings,
> Bal=E1zs
>=20
>=20
>=20
> -------------------------------------------------------
> This sf.net email is sponsored by:ThinkGeek
> Welcome to geek heaven.
> http://thinkgeek.com/sf
> _______________________________________________
> Dev-cpp-users mailing list
> Dev...@li...
> TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
> https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
>=20
|