Click here to Skip to main content
15,897,187 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionCBrush - color Pin
korte254-Jan-09 5:11
korte254-Jan-09 5:11 
AnswerRe: CBrush - color Pin
CPallini4-Jan-09 5:20
mveCPallini4-Jan-09 5:20 
GeneralRe: CBrush - color Pin
korte254-Jan-09 5:41
korte254-Jan-09 5:41 
GeneralRe: CBrush - color Pin
CPallini4-Jan-09 5:42
mveCPallini4-Jan-09 5:42 
QuestionWebbrowser control + ActiveX Pin
nobaq4-Jan-09 3:39
nobaq4-Jan-09 3:39 
QuestionRe: Webbrowser control + ActiveX Pin
nobaq4-Jan-09 4:10
nobaq4-Jan-09 4:10 
AnswerRe: Webbrowser control + ActiveX Pin
nobaq5-Jan-09 2:00
nobaq5-Jan-09 2:00 
Questionstatic-inheritance problem Pin
KasyaMafia4-Jan-09 3:32
KasyaMafia4-Jan-09 3:32 
Hello, I have a problem with static variables and inheritance

<br />
<br />
class BVolume {<br />
protected:<br />
enum { NONE = 0, SPHERE, BOX, PLANE };<br />
public:<br />
static const unsigned short type = NONE;<br />
<br />
virtual bool TestCollision(BVolume * volume)=0;<br />
<br />
};<br />
<br />


<br />
<br />
class BBox : public BVolume {<br />
public:<br />
static const unsigned short type = BOX;<br />
<br />
bool TestCollision(BVolume * volume) { return Collision< volume -> type >(volume); }<br />
<br />
template< unsigned short type > bool Collision(BVolume * volume) { return false; }<br />
<br />
template< > bool Collision< BOX >(BVolume * box) { return BoxCollision(static_cast< BBox * >(box)); }<br />
template< > bool Collision< SPHERE >(BVolume * sphere) { return SphereCollision(static_cast< BSphere * >(sphere)); }<br />
<br />
bool BoxCollision(BBox * box) { return true; } //For Testing That Code<br />
bool SphereCollision(BSphere * box) { return true; } //For Testing That Code (BSphere is for testing too)<br />
<br />
<br />
};<br />
<br />


<br />
<br />
BBox b1, b2;<br />
<br />
bool Collided() {<br />
<br />
return b1.TestCollision(&b2);<br />
<br />
}<br />
<br />
if(Collided()) std::cout << "Collided";<br />
else std::cout << "Not Collided";<br />
<br />


the code above outputs "Not Collided"

I found the problem but i don't know how to solve it.

Problem:

volume->type in BBox::TestCollision is NONE (it needs to be BOX or SPHERE here) because static is a Compile Time "Thing". I need something Run Time "Thing".

What can i do? Please Help me with that problem!

Thanks,
Kasya
QuestionRe: static-inheritance problem Pin
CPallini4-Jan-09 3:42
mveCPallini4-Jan-09 3:42 
AnswerRe: static-inheritance problem Pin
KasyaMafia4-Jan-09 4:33
KasyaMafia4-Jan-09 4:33 
GeneralRe: static-inheritance problem Pin
CPallini4-Jan-09 4:54
mveCPallini4-Jan-09 4:54 
GeneralRe: static-inheritance problem [modified] Pin
KasyaMafia4-Jan-09 5:59
KasyaMafia4-Jan-09 5:59 
QuestionRe: static-inheritance problem Pin
CPallini4-Jan-09 6:14
mveCPallini4-Jan-09 6:14 
JokeRe: static-inheritance problem Pin
Mark Salsbery4-Jan-09 6:42
Mark Salsbery4-Jan-09 6:42 
GeneralRe: static-inheritance problem Pin
CPallini4-Jan-09 10:17
mveCPallini4-Jan-09 10:17 
GeneralRe: static-inheritance problem Pin
Mark Salsbery4-Jan-09 15:22
Mark Salsbery4-Jan-09 15:22 
AnswerRe: static-inheritance problem Pin
KasyaMafia4-Jan-09 7:20
KasyaMafia4-Jan-09 7:20 
GeneralRe: static-inheritance problem Pin
CPallini4-Jan-09 10:10
mveCPallini4-Jan-09 10:10 
Question. Pin
ninjamafiakhan34-Jan-09 1:04
ninjamafiakhan34-Jan-09 1:04 
AnswerRe: Windows application control through Serial port Pin
Richard Andrew x644-Jan-09 2:05
professionalRichard Andrew x644-Jan-09 2:05 
GeneralMessage Closed Pin
4-Jan-09 2:17
ninjamafiakhan34-Jan-09 2:17 
GeneralRe: Windows application control through Serial port Pin
Richard Andrew x644-Jan-09 2:23
professionalRichard Andrew x644-Jan-09 2:23 
GeneralMessage Closed Pin
4-Jan-09 2:45
ninjamafiakhan34-Jan-09 2:45 
GeneralRe: Windows application control through Serial port Pin
Richard Andrew x644-Jan-09 2:57
professionalRichard Andrew x644-Jan-09 2:57 
GeneralRe: Windows application control through Serial port Pin
Jijo.Raj4-Jan-09 2:54
Jijo.Raj4-Jan-09 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.