initializer list err

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Mar 2007
Posts: 21
Reputation: desijays is an unknown quantity at this point 
Solved Threads: 1
desijays desijays is offline Offline
Newbie Poster

initializer list err

 
0
  #1
May 25th, 2007
  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: initializer list err

 
0
  #2
May 25th, 2007
  1.  
  2. // ...
  3. base( int t ) : i(t) {} // initialize member i with t
  4. // ...
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 21
Reputation: desijays is an unknown quantity at this point 
Solved Threads: 1
desijays desijays is offline Offline
Newbie Poster

Re: initializer list err

 
0
  #3
May 25th, 2007
Originally Posted by vijayan121 View Post
  1.  
  2. // ...
  3. base( int t ) : i(t) {} // initialize member i with t
  4. // ...
yes it works. but why doesn't this work

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,089
Reputation: vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all vijayan121 is a name known to all 
Solved Threads: 164
vijayan121 vijayan121 is offline Offline
Veteran Poster

Re: initializer list err

 
0
  #4
May 25th, 2007
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).
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC