944,007 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 2815
  • C++ RSS
May 25th, 2007
0

initializer list err

Expand Post »
C++ Syntax (Toggle Plain Text)
  1.  
  2.  
  3. class base
  4. {
  5. private:
  6. int i;
  7.  
  8. void seti( int i_temp ) // :i(i_temp) ->Initializer List not working
  9. {
  10. i = i_temp;
  11. }
  12.  
  13. public:
  14.  
  15. base()
  16. {
  17.  
  18. }
  19.  
  20. base( int t ):seti( t )
  21. {
  22.  
  23. }
  24. };
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?
Last edited by desijays; May 25th, 2007 at 4:08 am.
Similar Threads
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
May 25th, 2007
0

Re: initializer list err

C++ Syntax (Toggle Plain Text)
  1.  
  2. // ...
  3. base( int t ) : i(t) {} // initialize member i with t
  4. // ...
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006
May 25th, 2007
0

Re: initializer list err

Click to Expand / Collapse  Quote originally posted by vijayan121 ...
C++ Syntax (Toggle Plain Text)
  1.  
  2. // ...
  3. base( int t ) : i(t) {} // initialize member i with t
  4. // ...
yes it works. but why doesn't this work

C++ Syntax (Toggle Plain Text)
  1.  
  2. base( int t ): seti( t )
  3. {
  4.  
  5. }

Afterall im jus calling a private function to initialize 'i'.
Last edited by desijays; May 25th, 2007 at 7:44 am.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
desijays is offline Offline
21 posts
since Mar 2007
May 25th, 2007
0

Re: initializer list err

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).
Reputation Points: 1159
Solved Threads: 285
Posting Virtuoso
vijayan121 is offline Offline
1,606 posts
since Dec 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: I'm sure the answer is painfully obvious but....
Next Thread in C++ Forum Timeline: handheld telnet emulation





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC