I'm trying to use a constructor for a 'Control' class that takes no parameters but when I try to create an instance of it I get an error saying "No appropriate default constructor available"
Here is my header:
class Control
{
public:
Control();
private:
Layout activeLayout;
void createLayout();
void moveWindow(HWND hWnd, int X, int Y, int nWidth, int nHeight, std::string windowTitle);
void mainLoop();
};
#endif
My cpp file:
Control::Control()
{
Detector mainDetector();
createLayout();
mainLoop();
}
and where I try to call the instructor:
int _tmain(int argc, _TCHAR* argv[])
{
Control mainControl();
system("PAUSE");
return 0;
};
Pay attention that
Detector mainDetector();
is a function declaration, not the definition of a variable of type Control
. When there are no parameters the syntax is
Detector mainDetector;
There are cases in which the declaration of a local function is inferred even when it wouldn't seem possible... it's known as the "the most vexing parse" rule of C++.
A simple example is:
double pi = 3.141592654;
int int_pi(int(pi));
amazingly enough here int_pi
is declared to be a function!
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments