R
Robert
Hello all,
Why reference cannot be able to represent a NULL object?
Best regards,
Robert
Why reference cannot be able to represent a NULL object?
Best regards,
Robert
Hello all,
Why reference cannot be able to represent a NULL object?
Robert said:Hello all,
Why reference cannot be able to represent a NULL object?
Best regards,
Robert
Why reference cannot be able to represent a NULL object?
Best regards,
Robert
Hi,
I have a somewhat related question:
is it defined what happens to a reference after the object it references
is destroyed? It looks like there would be some sort of copy:
#include <iostream>
using namespace std;
class T {
public:
T(int i) {n=i;};
int n;
void speak(void) {cout << "Hello " << n << endl;};
};
class S{
public:
S(void) {};
void shout(void) {cout << "HEEYY!" << endl;};
};
int main(void)
{
T *t_ptr = new T(7);
T &t_ref = *t_ptr;
cout << "t_ptr: " << t_ptr << '\n'
<< "&t_ref: " << &t_ref << '\n';
t_ref.speak();
delete t_ptr;
t_ref.speak();
S *s_ptr = new S;
cout << "s_ptr: " << s_ptr << '\n'
<< "&t_ref: " << &t_ref << endl;
s_ptr->shout();
t_ref.speak();
delete s_ptr;
return 0;
}
produces:
t_ptr: 0x8049f40
&t_ref: 0x8049f40
Hello 7
Hello 0
s_ptr: 0x8049f40
&t_ref: 0x8049f40
HEEYY!
Hello 0
But why is the address the same?
Steffen
red said:With apologies to _Ghostbusters_, this is some of the things that
*could* happen:
* Fire and brimstone coming down from the skies. Rivers and seas boiling.
* Forty years of darkness. Earthquakes, volcanoes...
* The dead rising from the grave.
* Human sacrifice, dogs and cats living together - mass hysteria
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.