Advertisement

Constructors...?

Started by May 26, 2000 04:06 PM
1 comment, last by Fresh 24 years, 6 months ago
Hi, simple question: When inheriting a class, CBitmapImage, to CBitmapFont, I get an odd compiler message re: the constructor. The constructor for CBitmapImage is:

CBitmapImage::CBitmapImage(CDirectXEngine *g_DirectXEngine) {
	DirectXEngine = g_DirectXEngine;
}
 
and for CBitmapFont is:

CBitmapFont::CBitmapFont(CDirectXEngine *g_DirectXEngine, int char_width_in, int char_height_in) {
	DirectXEngine = g_DirectXEngine;

	char_width = char_width_in;
	char_height = char_height_in;
}
 
Now when I compile, CBitmapImage.cpp works fine, however the compiler throws up this message re: the CBitmapFont constructor: error C2512: ''CBitmapImage'' : no appropriate default constructor available I checked in the help files and this explanation was offered: "No default constructor was available for the specified class, structure, or union." "The compiler will supply a default constructor only if user-defined constructors are not provided. If you provide a constructor that takes a nonvoid parameter, then you must also provide a default constructor. The default constructor can be called with no parameters, that is, a constructor with default values for all parameters." This is something which I didn''t know anything about - can somebody explain in simple english what this means? This is obviously something to do with well...constructors. Thanx. r.
You might be trying to instanciate (spelling anyone?) a CBitmapImage buy you arent supplying it with the CDirectXEngine arguemnt. And there is no cBitmapImage::CBitmapImage() constructor... maybe...

==============================
"What if Bill Gates hade a penny everytime windows crashed?
Oh wait, he does!"
-Dont know who said that, but it's funny

-Joacim Jacobsson

spelling... *damn*



Edited by - Fisk on May 26, 2000 5:11:27 PM
=============================="What if Bill Gates hade a penny everytime windows crashed? Oh wait, he does!"-Dont know who said that, but it's funny :)-Joacim Jacobsson
Advertisement

Try using:

CBitmapFont::CBitmapFont(CDirectXEngine *g_DirectXEngine, int char_width_in, int char_height_in) : CBitmapImage(g_DirectXEngine){
...
}

The reason is that when you build an inherrited object you must first build the base object which is CBitmapImage. But you have no default constructor for this base class. You have to tell the inherrited class how to build the base class. The above is saying to build the CBitmapImage object using this constructor.

Or you could just define a default constructor in CBitmapImage.


Andrew

This topic is closed to new replies.

Advertisement