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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:43:16+00:00 2026-06-11T13:43:16+00:00

EDIT: RELATED TO c++ undefined reference to `vtable I am trying to do a

  • 0

EDIT: RELATED TO c++ undefined reference to `vtable

I am trying to do a project on inheritance and I’m getting this error:

/tmp/ccw1aT69.o: In function `main':
main.cpp:(.text+0x15): undefined reference to `Derived::Derived(int)'
/tmp/ccw1aT69.o: In function `Derived::~Derived()':
main.cpp:(.text._ZN20DerivedD2Ev[_ZN20DerivedD5Ev]+0x13): undefined reference to `vtable for Derived'
main.cpp:(.text._ZN20DerivedD2Ev[_ZN20DerivedD5Ev]+0x1f): undefined reference to `Base::~Base()'
collect2: ld returned 1 exit status

This is my code:

main.cpp:

#include <iostream>
#include "Base.h"
#include "Derived.h"

int main() {
    Derived intList(25);
}

base.h:

#ifndef BASE_H
#define BASE_H

class Base {
    public:
            ...
            Base (const Base& otherList);
            virtual ~Base();
    protected:
            int *list;
            int length;
            int maxSize;
};

#endif

Base.cpp:

#include "Base.h"
#include <iostream>

using namespace std;

...definitions of my members...

Base::Base (int size) {
//stuff
}
Base::~Base() {
    delete [] list;
}
Base::Base (const Base& otherList) {
//stuff
}

Derived.h:

#ifndef DERIVED_H
#define DERIVED_H
#include "Base.h"

class Derived: public Base {
    public:
             ...
            Derived (int size = 100);
            ~Derived(); //THIS LINE ADDED AFTER FIRST ANSWER
};

#endif

Derived.cpp:

#include "Derived.h"
#include <iostream>

using namespace std;

Derived::Derived (int size)
        :Base(size){
}

What causes this error? It looks like I can’t call the constructor, but it looks fine to me.

EDIT: I tried the first solution. Error now:

/tmp/ccA4XA0B.o: In function `main':
main.cpp:(.text+0x15): undefined reference to `Derived::Derived(int)'
main.cpp:(.text+0x21): undefined reference to `Derived::~Derived()'
collect2: ld returned 1 exit status
  • 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-06-11T13:43:18+00:00Added an answer on June 11, 2026 at 1:43 pm

    You have declared a virtual destructor in Base, yet you never define it. It needs to be defined in Derived (as well as in Base because it is not a pure virtual function) because it will be called once main exits. You should have:

    class Base {
    public:
        // ...
        virtual ~Base();
    };
    
    Base::~Base() {}
    
    class Derived : public Base {
    public:
        // ...
        ~Derived();
    };
    
    Derived::~Derived() { /* whatever */ }
    

    That is the cause of at least one of your errors. I don’t know if this one is a red herring or not, but it seems to be:

    /tmp/ccw1aT69.o: In function main':
    main.cpp:(.text+0x15): undefined reference to
    Derived::Derived(int)’

    You define Derived::Derived(int), so it’s hard to imagine that is a real error. Define your destructor and see if it goes away.

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

Sidebar

Related Questions

I'm getting undefined method `Carrots' for # (referencing ln#18) When trying to edit with
This is related to my previous question I'm solving UVA's Edit Step Ladders and
I need the form that will edit the array of entities and their related
EDIT 07/14 As Bill Burgess mentionned in a comment of his answer, this question
EDIT : It turned out that this can only be done through an external
I am getting a strange named helpers with this setup: In config/routes.rb I have:
I have this function correctly linked in an external .js file... function SubmitAge(age, UpdatePanelID,
Recently downloaded some code for a minor open-source project related to a small webgame
I am attempting to construct a formview that will edit two related objects at
This is one of the pages. When you click on the error icon at

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.