954,487 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

initializer list err

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?

desijays
Newbie Poster
21 posts since Mar 2007
Reputation Points: 10
Solved Threads: 1
 
// ...
        base( int t ) : i(t) {} // initialize member i with t
       // ...
vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 
// ...
        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'.

desijays
Newbie Poster
21 posts since Mar 2007
Reputation Points: 10
Solved Threads: 1
 

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).

vijayan121
Posting Virtuoso
1,606 posts since Dec 2006
Reputation Points: 1,159
Solved Threads: 287
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You