calling class function from constructor

This is a discussion on calling class function from constructor within the C++ Programming forums, part of the General Programming Boards category; Hello.. Can I call function somefunc this way (from constructor): Code: class someclass { public: someclass(int num, bool yes) : ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    calling class function from constructor

    Hello..

    Can I call function somefunc this way (from constructor):

    Code:
    class someclass {
    public:
    	someclass(int num, bool yes) : num_m(num), somefunc(num, yes) {
    	}
    	
    	int num_m;
    	void somefunc(int num, bool yes) {
    	}
    };
    Thanks again

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,754
    Have you even tried to compile?
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    Dec 2006
    Posts
    30
    you put a function call in the initializer list? that doesn't make any sense; did you mean this? the answer is generally yes (there are some obscure exceptions).

    Code:
    class someclass {
    public:
    	someclass(int num, bool yes) : num_m(num) {
              somefunc(num, yes);
    	}
    	
    	int num_m;
    	void somefunc(int num, bool yes) {
    	}
    };

  4. #4
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630
    I know this option is possible, but wasnt sure about calling function from initalizer.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 04:01 PM
  3. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21