Whats the syntax for getPrivateMember
Whats the syntax for a function defined in a class''s public area that return the private member variable all in one line?
I think its something like
class woho
{
public:
int getNumParticles(); {return m_numParticles}
the above doesnt work but i know it look something like that. Can anyone help out? Thanks
You''re making it out to be some sort of special construct: it is just a function like any other. It is just a function which returns a value (that just happens to be a private member.) So the return statement needs a semicolon like any nornal statement.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
if you want it really correct and fast us
or if you don't want to expose your implementation in your interface (generally a good idea) you can write a inline file like this...
class.h
class.ipp
"That's not a bug, it's a feature!"
--me
Edited by - ChaosEngine on February 1, 2002 3:35:54 AM
class woho{public: int getNumParticles() {return m_numParticles; } const;private: int m_numParticles;};
or if you don't want to expose your implementation in your interface (generally a good idea) you can write a inline file like this...
class.h
class woho{public: inline int getNumParticles() const;private: int m_numParticles;};#include "class.ipp"
class.ipp
inline int woho::getNumParticles() const;{ return m_numParticles;}
"That's not a bug, it's a feature!"
--me
Edited by - ChaosEngine on February 1, 2002 3:35:54 AM
The code posted by Chaos Engine will compile under MSVC (don''t know about other compilers).
For an inline function, the definition of the function has to be in the same header file as its declaration. Else if won''t compile.
For an inline function, the definition of the function has to be in the same header file as its declaration. Else if won''t compile.
quote:Original post by NuffSaid
For an inline function, the definition of the function has to be in the same header file as its declaration. Else if won''t compile.
No, the definition just needs to have been included (directly or indirectly) by every file which calls that inline function.
[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement