Thread: Daughter class not inheriting the function from the mother.

  1. #1
    Registered User
    Join Date
    Mar 2019
    Posts
    50

    Daughter class not inheriting the function from the mother.

    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    
    
    class Mother//Base Class
    {
    	public:
    		Mother();//daughter will not inhereit constructors or destructor
    		void sayName()//function will be inhereited
    		{
    			cout << "I am a Roberts!" << endl;
    		}
    };
    
    
    class Daughter: public Mother//Derived Class will inhereit functions from Mother
    {
    	public:
    		Daughter();
    };
    
    
    int main()
    {
    	Daughter tina;
    	tina.sayName();
    	return 0;	
    }
    Ok, so I TRIPPLE checked this wasnít a typo, whats going on here? Iím getting an error saying tried to execute an unknown external function. Itís like the daughter is not inhereiting the function from the mother.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,248
    What is the exact error message? Is this the complete program? I note you didn't define the constructors: I'd just leave them out.
    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
    Mar 2019
    Posts
    50
    Quote Originally Posted by laserlight View Post
    What is the exact error message? Is this the complete program? I note you didn't define the constructors: I'd just leave them out.
    That was it, it was the blank constructors, Ive noticed that this particular compiler DOES NOT CARE FOR THEM AT ALL. Removed them and everything worked perfect. FYI, yes this was complete. I remove all the non-pertinent code if its not a review problem which this was. Thanks LL.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    27,248
    It's not the compiler; it's the fact that your classes don't have any members that cannot be default constructed, and you didn't declare any other constructors.
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [SDL] Enemy class inheriting from tile class.
    By Kain in forum Game Programming
    Replies: 5
    Last Post: 01-29-2013, 12:46 PM
  2. Problem inheriting class getting infinite loop
    By joeba18 in forum C# Programming
    Replies: 3
    Last Post: 12-14-2010, 11:19 PM
  3. Using or inheriting a class
    By audinue in forum A Brief History of Cprogramming.com
    Replies: 2
    Last Post: 11-20-2008, 12:11 PM
  4. Class operators when inheriting
    By 39ster in forum C++ Programming
    Replies: 5
    Last Post: 07-14-2008, 06:13 AM
  5. Inheriting from specific templated version of class
    By skiingwiz in forum C++ Programming
    Replies: 4
    Last Post: 11-14-2004, 09:21 AM

Tags for this Thread