I recently saw the below code ( simplified version given below) in my code base and got this doubt:
class B;
class A
{
public:
A():m_A("testA"){}
B& getB()
{
return m_B;
}
B* getBPtr() //== > written to explain the problem clearly
{
return &m_B;
}
private:
B m_B;
};
class B
{
public:
B(const std::string& name):m_Name(name){}
std::string getName() const
{
return m_Name;
}
private:
std::string m_Name;
};
class C
{
public:
void testFunc(B* ptr)
{
}
};
int main()
{
A a;
C c;
c.testFunc(&a.getB()); ===> is it equivalent to c.testFunc(a.getBPtr()) ?
}
- The pointer to reference and pointer to actual variable can be treated as same?
- Does standard says anything on the address of reference to be interchangeable used for address of variable.