Sign in to follow this  
davidcoleman

Accessing classes-different ways

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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...

Share this post


Link to post
Share on other sites
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'.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this