-3

I've seen the above in some c++ code and wonder what is happening. Can anyone explain what this means to me?

SomeManager::SomeManager()
   : m_someinterface(NULL)
   , m_someinterface(NULL)
{
}
Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
Gavzooka
  • 57
  • 1
  • 9

1 Answers1

4

I think you mean the following

SomeManager::SomeManager() : m_someinterface(NULL) , m_someinterface(NULL)
{
}

It is a definition of a constructor of class SomeManager that have mem-initializer list

m_someinterface(NULL) , m_someinterface(NULL)

where its subobjects (data members and/or base class subobjects) are initialized.

Take into account that data members shall have different names like for example m_someinterface1 m_someinterface2.

Here is a simple example

class A
{
public:
    A();

private:    
    int x;
    int y;
};

A::A() : x( 10 ), y( 20 ) {}

After creating an object of the class like

A a;

its data members a.x and a.y will have correspondingly values 10 and 20.

Or another example where the base class constructor is called explicitly

class A
{
public:
    A( int x, int y ) : x( x ), y( y ) {}

private:    
    int x;
    int y;
};

class B : piblic A
{
public:
    B( int );

private:    
    int z;
};

B::B( int z ) :  A( z / 10, z % 10 ), z( z ) {}
Vlad from Moscow
  • 301,070
  • 26
  • 186
  • 335