0
class base
{
  private:
        int i;

        void seti( int i_temp ) // :i(i_temp) ->Initializer List not working
        {
             i = i_temp;
        }

  public:

        base()
        {

        }

        base( int t ):seti( t )
        {

        }
};

error C2436: 'seti' : member function or nested class in constructor initializer list.

That is the error i get for the code above it. could someone please tell me where im err-ing?

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by vijayan121
0
// ...
        base( int t ) : i(t) {} // initialize member i with t
       // ...

yes it works. but why doesn't this work

base( int t ): seti( t )
        {

        }

Afterall im jus calling a private function to initialize 'i'.

0

you can call functions inside the body of the constructor. colon initialization can be used only for initialization of members or base classes (using copy constructor semantics).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.