No appropriate default constructor available?
Solution 1
Got it! It occurred to me that I'd forward-declared the RawDataPacket class in the header of the Controller class.
I tried including the header in there and removing the forward declaration and it worked. So it turns out that despite forward-declaring the class I'd forgotten to include the header in Controller.cpp
That could have been a nasty one to find.. cheers for the help all!
Solution 2
use explicit before the constructor if you are having parameters for constructor.
Comments
-
Jon Cage almost 2 years
I've got a peculiar error writing some C++/CLI code. I'm trying to make a copy of a class which holds some data.
The class is defined as:
public ref class RawDataPacket { protected: float* m_internalData; public: RawDataPacket(const float* newInternalData); RawDataPacket(const RawDataPacket^ rdp); RawDataPacket(RawDataPacket^ rdp); RawDataPacket(); };
When I try and make use of the class as follows:
void SomeClass::SomeFunction( RawDataPacket^ rdp ) { // Send a copy of the packet to anyone interested. RawDataPacket^ rdp1 = gcnew RawDataPacket( rdp ); ForwardData( rdp1 ); }
I get:
error C2512: 'RawDataPacket' : no appropriate default constructor available
I thought that
RawDataPacket();
had that covered? ..or am I missing something really obvious there?[Edit] The body of
RawDataPacket()
looks like this:RawDataPacket::RawDataPacket() { m_internalData = nullptr; }
[Edit2] The full compiler output looks like this:
1>------ Build started: Project: MySoftware, Configuration: Debug Win32 ------ 1>Compiling... 1>RawDataPacket.cpp 1>Controller.cpp 1>.\Controller.cpp(452) : error C2512: 'MySoftware::RawDataPacket' : no appropriate default constructor available 1>Build log was saved at "file://c:\Projects\Experiments\MySoftware\Debug\BuildLog.htm" 1>MySoftware - 1 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========