Prototype syntax for sub-class constructor

This is a discussion on Prototype syntax for sub-class constructor within the C++ Programming forums, part of the General Programming Boards category; Folks, I'm trying to figure out the correct prototype syntax for the below constructor of my sub-class DEAD_CHARS and I ...

  1. #1
    Registered User starkhorn's Avatar
    Join Date
    Sep 2003
    Posts
    21

    Prototype syntax for sub-class constructor

    Folks,

    I'm trying to figure out the correct prototype syntax for the below constructor of my sub-class DEAD_CHARS and I was hoping someone would know how ?

    The below implementation compiles for my DEAD_CHAR class and works when I attempt to assign a CHARACTER object to a DEAD_CHAR object.

    Code:
    DEAD_CHARS(const CHARACTER &character, int turn_num = 5): CHARACTER(character){}

    However what is the correct syntax in order to prototype the below implementation so that I can have the prototype in a dead_chars.h and the implementation in a dead_chars.cpp file ?

    Cheers
    Starkhorn


    Here is the prototype in my dead_chars.h file for my DEAD_CHARS class. It's a sub-class of the super-class CHARACTER.

    Code:
    #include "character.h"
    
    using namespace std;
    
    class DEAD_CHARS : public CHARACTER
    {
    	public:
    	
    		DEAD_CHARS(); //Default constructor
    
    		DEAD_CHARS(const CHARACTER &character, int turn_num = 5): CHARACTER(character){}
    
    		int get_turn_death();
    
    		void set_turn_death(int turn_num);
    
    
    
    	private:
    
    		int turn_death;
    };
    
    #endif

  2. #2
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,660
    Code:
    DEAD_CHARS::DEAD_CHARS(const CHARACTER &character, int turn_num/*=5*/)
        : CHARACTER(character)
    {
        ...
    }//constructor
    The "=5" part will stay uncommented in the declaration in the header:
    Code:
        DEAD_CHARS(const CHARACTER &character, int turn_num = 5);
    gg

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. class composition constructor question...
    By andrea72 in forum C++ Programming
    Replies: 3
    Last Post: 04-03-2008, 05:11 PM
  3. template class default constructor problem
    By kocika73 in forum C++ Programming
    Replies: 3
    Last Post: 04-22-2006, 09:42 PM
  4. Replies: 3
    Last Post: 03-25-2006, 11:59 PM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

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