Reputation: 481
Is there any problem to return a reference of a static member variable? (Reference to avoid copy cost)
Vector accepts 4 parameters(x,y,z,w);
.h
class MyClass
{
private:
static const Vector POS;
}
.cpp
const Vector MyClass::POS(100,300,0,0);
const Vector& MyClass::GetVector()
{
return POS;
}
Upvotes: 0
Views: 3661
Reputation: 409166
If POS
is declared static
then its lifetime is the lifetime of the program, and so returning a reference to it is safe.
Upvotes: 6