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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:27:10+00:00 2026-05-16T14:27:10+00:00

Consider the following: In X.h: class X { X(); virtual ~X(); }; X.cpp: #include

  • 0

Consider the following:

In X.h:

class X
{
    X();
    virtual ~X();
};

X.cpp:

#include "X.h"

X::X()
{}

Try to build this (I’m using a .dll target to avoid an error on the missing main, and I’m using Visual Studio 2010):

Error 1 error LNK2001: unresolved external symbol “private: virtual __thiscall X::~X(void)” (??1X@@EAE@XZ)

Small modifications result in a successful build, however:

X.h:

class X
{
    inline X(); // Now inlined, and everything builds
    virtual ~X();
};

or

X.h:

class X
{
    X();
    ~X(); // No longer virtual, and everything builds
};

What causes the unresolved external in the linker when the .dtor is virtual or when the .ctor isn’t inlined?

EDIT:

Or, perhaps more interestingly, why do I not get an unresolved external if I make the destructor non-virtual, or if I inline the constructor?

  • 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-16T14:27:11+00:00Added an answer on May 16, 2026 at 2:27 pm

    Situation 1:

    You have the code for the constructor.
    So it builds the constructor into the object file. The constructor needs the address of the destructor to put into the virtual table because it can not find it the constructor can not be built.

    Situation 2: (inline constructor)

    The compiler decides it does not need to build the constructor (as it will be inlined).
    As such it does not plant any code and therefore does not need the address of the destructor.

    If you instanciate an object of type X it will again complain.

    Situation 3: (non virtual destructor)

    You don’t need the address of the destructor to build the constructor.
    So it does not complain.

    It will complain if you instantiate an object of type X.

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

Sidebar

Ask A Question

Stats

  • Questions 512k
  • Answers 512k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not a real solution but to prevent this… May 16, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer Maybe, the easiest way here is to add UINavigationController to… May 16, 2026 at 5:28 pm
  • Editorial Team
    Editorial Team added an answer Well, it depends on the language. It is a common… May 16, 2026 at 5:28 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Consider the following class structure: class Filter { virtual void filter() = 0; virtual
Consider the following set of classes/Interfaces: class IFish{ public: virtual void eat() = 0;
Consider the following code: class A { public: virtual void f() throw ( int
Consider the following class hierarchy: base class Object with a virtual method foo() an
Consider the following template class class MyClassInterface { public: virtual double foo(double) = 0;
Consider the following class: class Something : ISomething { public void DoesSomething(int x) {
Please consider the following code: class Abase{}; class A1:public Abase{}; class A2:public A1{}; //etc
Please, consider the following (I'm sorry for the amount of code; but this is
Consider the following code: class Program { static void Main(string[] args) { A a
Consider the following models: class Person(models.Model): name = models.CharField(max_length=128) class Group(models.Model): name = models.CharField(max_length=128)

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.