Domanda

I'm getting a linker error in VS2010 SP1 compiling and linking the code below, saying that it cannot find the symbol Base::Base(void).

Seems like the implicit default constructor does not get generated.

If I choose to initialize b as follows const Base& b = *d;, it just works fine. If I make d a Derived* it works. Finally if I make dosomething not pure virtual but virtual, it also works.

Is it a bug or am I doing something wrong ? I tried compiling the code online here http://www.compileonline.com/compile_cpp11_online.php and it works fine.

struct Base
{
    virtual void dosomething() const  = 0;
};

struct Derived : Base
{
    virtual void dosomething() const override { }
};

int main()
{
    Base* d = new Derived();
    const auto& b = *d;

    return 0;
}
È stato utile?

Soluzione

The code is fine WRT Base, nothing to prevent the ctor being generated. Looks like a bug in VS2010

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top