Thread View: de.comp.lang.c++
4 messages
4 total messages
Started by Jan Schiefer
Sat, 08 Aug 1992 09:57
Re: reference variables
Author: Jan Schiefer
Date: Sat, 08 Aug 1992 09:57
Date: Sat, 08 Aug 1992 09:57
19 lines
1103 bytes
1103 bytes
tmorgan@andromeda.rutgers.edu (Why? Only I Can Be Me) writes:
> I am having a problem finding documentation telling me whether a reference
> can be used in a c++ class. I am using Borland C++ 3.1 and it gives me an
Yes, class member functions can take references as parameters and return
references. It is also possible to have a reference as a data member, but it
must be initialized properly.
> error when I try to do it. However, I am not able to figure out how to do it
> or why I get the error. So...is it possible. If so, how 'bout an example.
What are you trying to do? What error do you get?
Cheers,
Jan
--
Jan Schiefer, DL5UE, jan@nasobem.stgt.sub.org
"Oracle et laboracle!" - Fritz Hohl
Re: reference variables
Author: Why? Only I Can Be Me
Date: Tue, 11 Aug 1992 15:30
Date: Tue, 11 Aug 1992 15:30
17 lines
770 bytes
770 bytes
I do something similar to the following:
class X {
int &var ;
public:
constructor that initializes var...doesn't work.
destructor
rest of functions
.
.
.
} ;
I don't remember the error that I am getting, as I am doing this from memory.
I hope that what I gave you helps solve my dilemma.
Thanks,
Talib
Re: reference variables
Author: Andre Pareis
Date: Wed, 12 Aug 1992 15:36
Date: Wed, 12 Aug 1992 15:36
34 lines
1615 bytes
1615 bytes
In article <Aug.11.11.30.04.1992.28134@andromeda.rutgers.edu>, tmorgan@andromeda.rutgers.edu (Why? Only I Can Be Me) writes:
|> I do something similar to the following:
|> class X {
|> int &var ;
|> public:
|> constructor that initializes var...doesn't work.
|> destructor
|> rest of functions
|> .
|> .
|> .
|> } ;
|>
|> I don't remember the error that I am getting, as I am doing this from memory.
|> I hope that what I gave you helps solve my dilemma.
|>
|> Thanks,
|> Talib
In Tom Swan's 'Learning C++' I found some lines about this problem.
One must convert this reference into a pointer, then all should work.
I'll read this part again and then tell the solution, but, since I borrowed
the book it could take some time.
--
-----------------------------------------------
| Andr'e Pareis, |
| Internet: pareis@cs.tu-berlin.de |
| subiaagb@w350zrz.zrz.tu-berlin.de |
-----------------------------------------------
Re: reference variables
Author: Dr. Raimund K. Ege
Date: Thu, 13 Aug 1992 18:56
Date: Thu, 13 Aug 1992 18:56
46 lines
1925 bytes
1925 bytes
In article <2QZ5GEP@mailgzrz.tu-berlin.de>, subiaagb@w350zrz.tu-berlin.de (Andre Pareis) writes:
|> In article <Aug.11.11.30.04.1992.28134@andromeda.rutgers.edu>, tmorgan@andromeda.rutgers.edu (Why? Only I Can Be Me) writes:
|> |> I do something similar to the following:
|> |> class X {
|> |> int &var ;
|> |> public:
|> |> constructor that initializes var...doesn't work.
|> |> destructor
|> |> rest of functions
|> |> .
|> |> .
|> |> .
|> |> } ;
|> |>
|> |> I don't remember the error that I am getting, as I am doing this from memory.
|> |> I hope that what I gave you helps solve my dilemma.
|> |>
|> |> Thanks,
|> |> Talib
|>
|>
|> In Tom Swan's 'Learning C++' I found some lines about this problem.
|> One must convert this reference into a pointer, then all should work.
|> I'll read this part again and then tell the solution, but, since I borrowed
|> the book it could take some time.
|>
Das Problem liegt im Constructor.
Hier die Loesung:
class X {
int &var;
public:
X(int i):var(i) {
...
}
.
.
};
--
Raimund K. Ege School of Computer Science
Florida Int'l University
ege@scs.fiu.edu (305) 348-3381 University Park
ege@servax.bitnet FAX (305) 348-3549 Miami, FL 33199
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads