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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:07:03+00:00 2026-05-23T11:07:03+00:00

I ran into a surprising revelation when implementing the pimpl idiom with a home

  • 0

I ran into a surprising revelation when implementing the pimpl idiom with a home made pointer class (I know: why roll your own? But bear with me). The following three files contain a minimal example:

Pointer.h:

#pragma once 

template <typename T>
class Pointer
{
public:
    Pointer(T*p=0)
        : _p(p)
    {
    }
    virtual ~Pointer()
    {
        delete _p;
    }
private:
    void operator=(const Pointer&);
    Pointer(const Pointer&);

private:
    T*_p;
};

Foo.h:

#pragma once
#include "Pointer.h"

struct Foo
{
    Foo();
    ~Foo();

private:
    void operator=(const Foo&);
    Foo(const Foo&);

private:
    Pointer<struct FooPrivate> p;
};

main.cpp:

#include "Foo.h"

int main(int argc, char* argv[])
{
    Foo foo;
    return 0;
}

Never mind what the innards of Foo.cpp look like. When I compile main.cpp with MSVC 2008, I get the warning:

pointer.h(13) : warning C4150: deletion of pointer to incomplete type 'FooPrivate'; no destructor called

The warning can be avoided by removing the keyword virtual from Pointers destructor.

This makes no sense to me. Is this warning legit, or is it a bug in the MSVC compiler? If so, can I safely ignore the warning?

I know it makes no sense in this case to make the destructor virtual, but remember, this is just a minimal compilable example. My original code is a lot more complex.

  • 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-23T11:07:04+00:00Added an answer on May 23, 2026 at 11:07 am

    Without virtual, there is only one place the destructor is going to be called; within ~Foo, at which point you have presumably fully defined FooPrivate. If another instance of Pointer<FooPrivate> is created elsewhere, you might get the warning back, but since you don’t the compiler can tell you’re behaving safely.

    With virtual, you can theoretically derive from Pointer<FooPrivate>, and that new object could be destroyed from somewhere that FooPrivate isn’t fully defined. The compiler isn’t positive you don’t do this, so it issues a warning. You can safely ignore it in this trivial case, but if you have an actual need for a virtual destructor it might be a good idea to take it to heart.

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

Sidebar

Related Questions

Ran into something interesting, want to know if I'm doing something wrong or if
I ran into a rather odd behavior that I don't even know how to
I ran into problems when trying to xml serialize a class to xml after
Ran into an issue with a class; I have a class that looks like:
Ran into an Out of Stack Space error trying to serialize an ASP.Net AJAX
I ran into an issue with an IIS web app shutting down an idle
I ran into an interesting (and very frustrating) issue with the equals() method today
I ran into the problem that my primary key sequence is not in sync
I ran into an interesting behavior recently. It seems that if I override .equals()
I ran into a scenario where LINQ to SQL acts very strangely. I would

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.