no appropriate default constructor available
I''m trying to implement abstaction but the following error occurres. I just can''t find a way to solve it.
error C2512: ''GFX_Win32_OpenGL'' : no appropriate default constructor available
//FILE: gfx.h
// includes abstract class
class GFX
{
public:
virtual void Render() = 0;
};
// FILE: gfx_win32_opengl.cpp
// implementation for win32 & OGL
// note: I include functions directly to cpp file with class, no
// include file used for each class.
class GFX_Win32_OpenGL : public GFX
{
public:
void Render()
{
// blaa blaa
}
};
// FILE main.cpp
// just trying to create new GFX
class GFX_Win32_OpenGL;
class GFX_Win32_D3D;
GFX *g_pGFX = 0L;
void main()
{
if( bUseOpenGL )
g_pGFX = new GFX_Win32_OpenGL;
else
g_pGFX = new GFX_Win32_D3D;
}
Thanks for your time!
ps. how can I put my code into white boxes. I''v seen may doing so! Thanks!
Did you create a constructor?
Every class should have a constructor and a destructor. Declare it like this:
.h file:
Edited by - Imois on July 4, 2001 1:33:58 PM
Every class should have a constructor and a destructor. Declare it like this:
.h file:
|
Edited by - Imois on July 4, 2001 1:33:58 PM
there is a default constructor for that class, but it''s not available since the class definition isn''t in scope where you try to instance it in main.
you can''t create an instance of a class with only a forward declaration, there must be a definition available. so, put your class definitions in headers, implimentations in .cpp''s, and then #include the appropriate header in your main.cpp.
you can''t create an instance of a class with only a forward declaration, there must be a definition available. so, put your class definitions in headers, implimentations in .cpp''s, and then #include the appropriate header in your main.cpp.
I''ve tried the constructors, but it won''t help. My constructors doesn''t get any parameters.
Obviously it works well, if I put the class GFX_Win32_OpenGL to include file.
But in my case I''d like to have the class only in one cpp file and then just include the lines
class GFX_Win32_OpenGL;
class GFX_Win32_D3D;
in the file where the object is created. But this gives an error. Isn''t the lines above enought to enable using the class.
Obviously it works well, if I put the class GFX_Win32_OpenGL to include file.
But in my case I''d like to have the class only in one cpp file and then just include the lines
class GFX_Win32_OpenGL;
class GFX_Win32_D3D;
in the file where the object is created. But this gives an error. Isn''t the lines above enought to enable using the class.
Bobtree: I was just answering Imois while you pushed your reply.
I was afraid it would be so I have to put my class definition to header file. Just thinking of tidier solution..?
I was afraid it would be so I have to put my class definition to header file. Just thinking of tidier solution..?
Stefu, I think you don't understand something.
First, there is the object declaration, and the object definition.
The declaration is usually in the header file like the following :
First, there is the object declaration, and the object definition.
The declaration is usually in the header file like the following :
|
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement