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

  • Home
  • SEARCH
  • 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 6600919
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:41:10+00:00 2026-05-25T18:41:10+00:00

Possible Duplicate: GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference

  • 0

Possible Duplicate:
GCC C++ Linker errors: Undefined reference to 'vtable for XXX', Undefined reference to 'ClassName::ClassName()'

I have been banging my head against a wall for a long time because of a strange ld error.
So I reproduced it in a small test case to understand the issue.

I declared a class and I derived another one in a header file:

class BaseClass {
public:
  BaseClass(){};
  virtual void func(){};
};

class DerivedClass: public BaseClass {
public:
  DerivedClass();
  void func();
};

Then I defined the constructor but forgot to define func (voluntary here, but that actually what I did with a silly copy/paste…):

DerivedClass::DerivedClass(){
  cout << "Derived constructor" << endl;
}

//void DerivedClass::func(){
//  cout << "Derived func" << endl;
//}

Then I get:

undefined reference to `vtable for DerivedClass’

Edit: And the message points the declaration of the consctructor!

If I uncomment the definition of func, then I have no error. So my question:
Why does the linker didn’t tell me that the definition of func is missing?

The solution might be obvious when you are experienced, but for a beginner like me it’s not!

Thanks for your help.

  • 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-25T18:41:11+00:00Added an answer on May 25, 2026 at 6:41 pm

    vtable is created for the class that contains virtual function and for the classes derived from it.It means in your program vtable will be created for BaseClass and DerivedClass.Each of these vtables would contain the address of virtual function void func().Now note that DerivedClass doesn’t contain the definition of void func(),hence its vtable contains the address of BaseClass‘s void func() function.That’s why the compiler is giving error undefined reference to vtable for DerivedClass.

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

Sidebar

Related Questions

Possible Duplicate: Should a function have only one return statement? Hello, gcc 4.4.4 c89
Possible Duplicate: Why does gcc have “â” in all its error messages? New to
Possible Duplicate: Making an undefined class as friend, and defining it later. I have
Possible Duplicate: What Ruby IDE do you prefer? I've generally been doing stuff on
Possible Duplicate: How does the Google Did you mean? Algorithm work? Suppose you have
Possible Duplicate: problem with template inheritance This code doesn't compile in GCC: template <typename
Possible Duplicate: How do you get assembler output from C/C++ source in gcc? Hello
Possible Duplicate: Creating ELF instead of a.out When I use the command gcc hello.cpp
Possible Duplicate: Get path of executable I'm programming on Windows using MinGW, gcc 4.4.3.
Possible Duplicate: Selectively disable GCC warnings for only part of a translation unit? How

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.