Thread: Do constructors get inherited?

  1. #16
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Originally posted by FillYourBrain

    nope. you're thinking destructors
    I was looking at facemasters code.

    http://www.cprogramming.com/cboard/s...threadid=23779

    Personally I have not used classes in about 6 months. I'm reading some c++ stuff but the book doesn't deal with classes until about page 200.

  2. #17
    Shadow12345
    Guest
    I have a default constructor in the base class...and it still doesn't work. I'm just going to post my ENTIRE source code for this because I'm bumming and I don't see what is wrong....it is more than likely simple and I will feel silly for not noticing it

    Code:
    //This is the human program
    //The class is class human
    //Here is a list of different attritutes to be included:
    /*
    physical attributes
    [pa]
    	Hair color, eye color, height, weight, skin color, 
    
    */
    
    
    //I want to create parents.  And then each human will have two parent humans
    //Each attribute needs to be mostly affected by the two parent's attributes, but also by chance
    //
    
    
    #include <windows.h>
    #include <iostream>
    #include <string>
    #include <conio.h>
    #include <time.h>
    #include <fstream>
    
    
    
    using namespace std;
    
    ofstream fout;		//used for outputting all of the data
    
    class Parent{
    public:
    	
    	Parent(string Name);
    	//static void Randomize(void) {srand(GetTickCount());}
    
    void Synopsis();
    
    void OutPutData();
    
    protected:
    		//physical attributes
    		string Name;
    		int SkinColor,
    		HairColor,
    		EyeColor, 
    		Height, 
    		Weight,
    
    		Intelligence,
    		Temper,
    		SelfEsteem,
    		Reasonableness;
    };
    
    
    
    
    
    
    Parent::Parent(string name) {
    
    	Name = name;
    	
    	SkinColor = rand()%5;
    
    	HairColor = rand()%5;
    
    	EyeColor = rand()%5;
    
    	Height = (rand()%36) + 36; //mexico sucks
    
    	Weight = (rand()%200) + 70;
    
    	Intelligence = rand()%5;
    
    
    	
    };
    
    void Parent::OutPutData()	{
    	fout << endl;
    
    	fout << "Here are the attributes for " << Name << endl;
    	cout << "Here are the attributes for " << Name << endl;
    
    	fout << "SkinColor " << SkinColor << endl;
    	cout << "SkinColor " << SkinColor << endl;
    
    	fout << "HairColor " << HairColor << endl;
    	cout << "HairColor " << HairColor << endl;
    
    	fout << "EyeColor " << EyeColor << endl;
    	cout << "EyeColor " << EyeColor << endl;
    
    	fout << "Weight " << Weight << " pounds " << endl;
    	cout << "Weight " << Weight << " pounds " << endl;
    
    	fout << "Height " << Height << " inches," << (Height/12) << " feet" <<   endl;
    	cout << "Height " << Height << " inches," << (Height/12) << " feet" <<   endl;
    
    	fout << "Intelligence " << Intelligence << endl;
    	cout << "Intelligence " << Intelligence << endl;
    
    	fout << endl;
    
    
    	};
    
    void Parent::Synopsis() {
    	switch(SkinColor) {
    	case 0:
    		{
    			cout << Name << " has a very light skin color" << endl;
    			break;
    		}
    
    	case 1:
    		{
    			cout << Name << " has a light skin color" << endl;
    			break;
    		}
    	case 2:
    		{
    			cout << Name << " has a somewhat light skin color" << endl;
    			break;
    		}
    	case 3:
    		{
    			cout << Name << " has a somewhat dark skin color" << endl;
    			break;
    		}
    	case 4: 
    		{
    			cout << Name << " has a dark skin color" << endl;
    			break;
    		}
    	case 5:
    		{
    			cout << Name << " has a very dark skin color" << endl;
    			break;
    		}
    	default:
    		{
    			cout << "I honestly don't know how you got her, but somehow you did, and you suck for it" << endl;
    		}
    	}
    }
    
    		
    	
    
    class Human : public Parent {
    public:
    
    private:
    
    
    };
    
    
    		
    int main(void) {
    	fout.open("Generated.txt");
    
    
    srand(GetTickCount());
    
    	Human Charles("Charles");
    
    	Human Jessica("Jessica");
    
    	Human Bob("Bob");
    
    	Human Frank("Frank");
    
    	Human Emmy("Emmy");
    
    	Human Rachel("Rachel");
    
    	Charles.OutPutData();
    	Charles.Synopsis();
    	getch();
    	system("cls");
    
    	Jessica.OutPutData();
    	Jessica.Synopsis();
    	getch();
    	system("cls");
    
    
    	Bob.OutPutData();
    	Bob.Synopsis();
    	getch();
    	system("cls");
    
    	Frank.OutPutData();
    	Frank.Synopsis();
    	getch();
    	system("cls");
    
    	Emmy.OutPutData();
    	Emmy.Synopsis();
    	getch();
    	system("cls");
    
    	Rachel.OutPutData();
    	Rachel.Synopsis();
    	getch();
    	system("cls");
    	fout.close();
    
    
    	return 0;
    }
    It really is a lot

    edit
    there are many logical problems but those aren't what is stopping the program for working, i.e I don't have all the protected member varialbes initialized in the constructor when I planned on having them all be initialized. I also didn't include a synopsis for all of the variables, so far just skin color
    edit
    Last edited by Shadow12345; 08-21-2002 at 11:15 AM.

  3. #18
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Code:
    class Human : public Parent {
    public:
    	Human(string name) : Parent(name) {}
    
    private:
    
    
    };
    Bada boom

  4. #19
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    Well I'll be a monkeys uncle.

  5. #20
    Shadow12345
    Guest
    Uhh it compiles but crashes when I run it with that modification

  6. #21
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    I'd put some destrutors in my classes.

  7. #22
    Shadow12345
    Guest
    that's not necessary at the moment I just can't figure out why it doesn't run

  8. #23
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    Funny, it worked perfectly for me (it generated the randon stats, sent them to the file, all formatted and everything)

  9. #24
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    I just added that one line from the code you posted before... and it worked fine

    What compiler are you using?

  10. #25
    Shadow12345
    Guest
    WHAT? you've gotta be joking...I'm using visual studio right now

  11. #26
    Shadow12345
    Guest
    As soon as I execute it, it crashes

  12. #27
    Shadow12345
    Guest
    Sweetness, I started a new project and it works...hey thanks for helping me, I hope you don't think I'm too much of a turd...I'm really only a small turd with bigger problems.

  13. #28
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    I'm using VC++ as well, I was about to tell you to 'clean' the project, but... you fixed it

    N/P btw

  14. #29
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    It compiled and ran under g++ after I got rid of all the non standard proprietry code.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help With Inherited Classes Needed
    By elliott in forum C++ Programming
    Replies: 4
    Last Post: 12-11-2005, 08:05 AM
  2. constructors, arrays, and new
    By Thantos in forum C++ Programming
    Replies: 6
    Last Post: 05-30-2004, 06:21 PM
  3. Inherited constructors with parameters
    By dave74 in forum C++ Programming
    Replies: 3
    Last Post: 11-20-2003, 10:27 AM
  4. Replies: 4
    Last Post: 12-28-2002, 11:29 PM
  5. Copy constructors and private constructors
    By Eibro in forum C++ Programming
    Replies: 5
    Last Post: 11-24-2002, 09:16 AM