Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6171169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:10:01+00:00 2026-05-23T23:10:01+00:00

I have a class Child and a class Human where Human has all the

  • 0

I have a class Child and a class Human where Human has all the functions declared in Child as virtual functions. And a class Child inherits from Human class.

I want to use Human as a interface file to hide implementation in Child.

I didn’t really set up a constructor, but I set up an init() function which initializes basic settings.

Now, what is a good way that I can use Child functions using Human interface file?

I tried

Human *John = new Child();

but I got the following errors.

main.cpp:7: error: expected type-specifier before ‘Child’
main.cpp:7: error: cannot convert ‘int*’ to ‘Human*’ in initialization
main.cpp:7: error: expected ‘,’ or ‘;’ before ‘Child

I don’t understand where int* came from either. None of my functions declared returns int*.

edit

main.cpp

#include <stdlib.h>
#include <stdio.h>
#include "Human.h"
using namespace std;
int main(){

    Human *John = new Child();

    return 0;
}

human.h

#ifndef __HUMAN_h__
#define __HUMAN_h__


class Human
{
public:
    virtual void Init() = 0;
    virtual void Cleanup() = 0;
};


#endif

Child.h

#ifndef __CHILD_h__
#define __CHILD_h__

#include "Human.h"


class Child : public Human
{
public:
    void Init();
    void Cleanup();

};

#endif

Child.cpp

#include "Child.h"
void Child::Init()
{
}

void Child::Cleanup()
{
}

Makefile

CC = g++
INC = -I.
FLAGS = -W -Wall
LINKOPTS = -g

all: program

program: main.o Child.o
    $(CC) -Wall -o program main.o Child.o

main.o: main.cpp Human.h
    $(CC) -Wall -c main.cpp Human.h

Child.o: Child.cpp Child.h
    $(CC) -Wall -c Child.cpp Child.h

Child.h: Human.h

clean:
    rm -rf program
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:10:03+00:00Added an answer on May 23, 2026 at 11:10 pm

    You need to #include "Child.h" in your cpp file. You can do this along with including human.h or you can not include human.h as that will be brought in automatically by the include within child.h

    #include <stdlib.h>
    #include <stdio.h>
    #include "Child.h"
    #include "Human.h"    // This is no longer necessary, as child.h includes it  
    using namespace std;
    int main(){
        Human *John = new Child();
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have child class,the child class inherits all methods from the parent,but how
Suppose I have a Base class and a Child class that inherits from Base
I have a templated class Child which inherits from a non-templated Parent class. When
I have a parent class and child class (inherited from parent). In the child
I have one abstract class and many child classes. In child classes are from
I have a class Child which does not have a ParentId property but has
i have a child Class, that needs an Annotation, that is declared in the
I have a abstract class which has some common methods for all of my
I have a base class Character which has several classes deriving from it. The
In a situation where you have a parent class which has one child class,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.