0

in the code below, it has the following line

 base_list(const base_list &tmp) :memory::SqlAlloc()

base_list is a method, memory is a namespace, SqlAlloc is a class, so what does it mean when combine them together?

class base_list :public memory::SqlAlloc
{
public:
  base_list(const base_list &tmp) :memory::SqlAlloc()
  {
    elements= tmp.elements;
    first= tmp.first;
    last= elements ? tmp.last : &first;
  }
Alok Save
  • 202,538
  • 53
  • 430
  • 533
mysql guy
  • 245
  • 1
  • 8

5 Answers5

3
base_list(const base_list &tmp) :memory::SqlAlloc() 

Uses Initializer list to call constructor of class SqlAlloc inside namespace memory.

For more information on advantages of using Initializer List in C++, See this.

Alok Save
  • 202,538
  • 53
  • 430
  • 533
2

It calls the default constructor of the base class memory::SqlAlloc().

namespace memory {

class SqlAlloc
{
public:
    SqlAlloc() {} // SqlAlloc's default constructor
};

}

//...

class base_list : public memory::SqlAlloc
{
public:
  // base_list constructor
  base_list(const base_list &tmp) : memory::SqlAlloc()
  {
   // The code after the ":" above and before the "{" brace
   // is the initializer list
    elements= tmp.elements;
    first= tmp.first;
    last= elements ? tmp.last : &first;
  };

Consider the following:

int main()
{
    base_list bl; // instance of base_list called "bl" is declared.
}

When bl is created, it calls the constructor of base_list. This causes the code in the initializer list of the base_list constructor to run. That initializer list has memory::SqlAlloc(), which calls SqlAlloc's default constructor. When SqlAlloc's constructor finishes, then the base_list's constructor is run.

In silico
  • 51,091
  • 10
  • 150
  • 143
1

base_list is the constructor and it's calling the constructor of the base class (SqlAlloc).

RBaarda
  • 558
  • 3
  • 10
1

:memory::SqlAlloc() calls the base class's default contructor and is as such not required here;

The syntax is called: (base) initializer list, see also Difference between initializer and default initializer list in c++

Community
  • 1
  • 1
sehe
  • 374,641
  • 47
  • 450
  • 633
0

base_list inherits from memory::SqlAlloc.

The line you ask about is the copy constructor. The : memory::SqlAlloc() after is the base class initializer. It calls the constructor of the base class.

Zan Lynx
  • 53,022
  • 10
  • 79
  • 131