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 7531969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T05:19:02+00:00 2026-05-30T05:19:02+00:00

File A.h #ifndef A_H_ #define A_H_ class A { public: virtual ~A(); virtual void

  • 0

File A.h

#ifndef A_H_
#define A_H_

class A {
public:
    virtual ~A();
    virtual void doWork();
};

#endif

File Child.h

#ifndef CHILD_H_
#define CHILD_H_

#include "A.h"

class Child: public A {
private:
    int x,y;
public:
    Child();
    ~Child();
    void doWork();
};
#endif

And Child.cpp

#include "Child.h"

Child::Child(){
    x = 5;
}

Child::~Child(){...}

void Child::doWork(){...};

The compiler says that there is a undefined reference to vtable for A.
I have tried lots of different things and yet none have worked.

My objective is for class A to be an Interface, and to seperate implementation code from headers.

  • 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-30T05:19:04+00:00Added an answer on May 30, 2026 at 5:19 am

    Why the error & how to resolve it?

    You need to provide definitions for all virtual functions in class A. Only pure virtual functions are allowed to have no definitions.

    i.e: In class A both the methods:

    virtual ~A();
    virtual void doWork();
    

    should be defined(should have a body)

    e.g.:

    A.cpp

    void A::doWork()
    {
    }
    A::~A()
    {
    }
    

    Caveat:
    If you want your class A to act as an interface(a.k.a Abstract class in C++) then you should make the method pure virtual.

    virtual void doWork() = 0;
    

    Good Read:

    What does it mean that the “virtual table” is an unresolved external?
    When building C++, the linker says my constructors, destructors or virtual tables are undefined.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

FILE #1 (foo.h): #ifndef FOO_H_ #define FOO_H_ #include baseclass.h #include bar.h class Bar; class
I have created MutexCondition class like this /*MutexCondtion.h file*/ #ifndef MUTEXCONDITION_H_ #define MUTEXCONDITION_H_ #include
I have a header file with all the enums listed (#ifndef #define #endif construct
When I have a header file like this: #ifndef GAMEVIEW_H_ #define GAMEVIEW_H_ #include <SDL/SDL.h>
There is one header a file Rectangle.hxx #ifndef Rectangle_included #define Rectangle_included #include <iostream> #include
I have a Mammal.h file that reads: #ifndef MAMMAL_H #define MAMMAL_H class Mammal {
I've created my own model class: #ifndef FILE_LISTING_MODEL_H #define FILE_LISTING_MODEL_H #include <QAbstractItemModel> #include <QStringList>
I have a .h file with this in it: #ifndef CS240_LINKED_LIST_H #define CS240_LINKED_LIST_H #include
I have the following header file: #ifndef DATABASE_H #define DATABASE_H #include <vector> #include <iostream>
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //

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.