Accessing classes-different ways

Started by
1 comment, last by swiftcoder 15 years, 5 months ago
I have looked at some source code and noticed that class is interfaced different ways m_CSomething.SomeFunction(); m_CSomething->SomeFunction(); &CSomething::SomeFunction(); When do I use which version? Does it make difference if I use #include in my .h or .cpp file? How do I share single instance of a class between different classes, what do I need to include where? Considering naming convention, is the CSomething m_CSomething; most standard way? Thanks!
Advertisement
Sorry I can't really help you because I've been curious about the same thing too.

But I'm curious as to what the m stands for in the naming conventions a lot of people seem to use (m_CSomething), if anyone could tell me...
Quote:Original post by davidcoleman
I have looked at some source code and noticed that class is interfaced different ways

m_CSomething.SomeFunction();
m_CSomething->SomeFunction();
&CSomething::SomeFunction();

When do I use which version?

something.func() calls a member function on an object instance named 'something'.
something->func() calls a member function on a pointer variable named 'something'.
Something::func() calls a static member of a class named 'Something'

Quote:Does it make difference if I use #include in my .h or .cpp file?
If you need the included file in your header file, included it there, otherwise include it only in your source file to reduce dependencies.

Quote:Considering naming convention, is the
CSomething m_CSomething;
most standard way?
It is workable, but clunky - the C and m_C prefixes are unnecessary. Prefer something simple, like this:
class Something // class{};Something something; // instance


Quote:Original post by Jaqen
But I'm curious as to what the m stands for in the naming conventions a lot of people seem to use (m_CSomething), if anyone could tell me...
Usually 'member', when used for instance variables - occasionally 'my'.

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

This topic is closed to new replies.

Advertisement