class Box
{
public:
void set(Data *pData)
{
m_pData = pData;
}
private:
Data * m_pData;
};
class Box
{
public:
void set(Data &data)
{
m_data = data;
}
private:
Data &m_data;
};
class Box
{
public:
void set(Data *pData)
{
m_pData = pData;
}
private:
Data * m_pData;
};
class Box
{
public:
void set(Data &data)
{
m_data = data;
}
private:
Data &m_data;
};
class Box{public: Box(Data &data) : m_data(data) { }private: Data &m_data;}Quote:
Original post by Sure Shot
They don't. Data &data is a reference, which is like a dereferenced constant pointer. So, Data &data would really be the equivalent of:References are mainly used in the copy-constructor and to pass objects to functions.const Data **data;
const Data **data; with 2 stars (*)? I belive it is just const Data* data; Feel free to correct if I'm wrong.
Quote:
Original post by GekkoCube
what is the difference (if any) between the two following setups:
void function ( void ){ int a = 1; int b = 2; int * pointer; pointer = &a; //pointer now points to a. (a == 1)&&(b == 2)&&(*pointer == 1) pointer = &b; //pointer now points to b. (a == 1)&&(b == 2)&&(*pointer == 2) *pointer = 3; //pointer now points to b. (a == 1)&&(b == 3)&&(*pointer == 3) int & reference ( a ); //must allways initialize a reference!!! //could be written as int & reference = a; , but I prefer not to. reference = a; //same as a = a. (a == 1)&&(b == 2)&&(reference == 1) reference = b; //same as a = b. (a == 3)&&(b == 3)&&(reference == 3) reference = 4; //same as a = 4. (a == 4)&&(b == 4)&&(reference == 4)}Quote:
Am I confusing myself here or do the two accomplish the same thing?
class Box{public: void set( Data * pData ) { *m_pData = *pData; }private: Data * m_pData;};
Quote:
Original post by Sure Shot
They don't. Data &data is a reference, which is like a dereferenced constant pointer. So, Data &data would really be the equivalent of:References are mainly used in the copy-constructor and to pass objects to functions.const Data **data;
This topic has been locked by a moderator. New replies are not allowed.
With your permission, GameDev.net uses analytics cookies to understand how people use the platform. You can accept analytics or continue with necessary cookies only. Learn more