Thread: calling class function from constructor

  1. #1
    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
    28,413
    Have you even tried to compile?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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
    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, 05: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