Code: Select all
class stageObject
{
public:
stageObjectType type; //hector, pipe, food, etc.
stageObject();
virtual void update()=0;
virtual void draw()=0;
};
Moderator: Coders of Rage
Code: Select all
class stageObject
{
public:
stageObjectType type; //hector, pipe, food, etc.
stageObject();
virtual void update()=0;
virtual void draw()=0;
};
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Code: Select all
virtual void update()=0;
virtual void draw()=0;
Code: Select all
virtual void update() {};
virtual void draw() {};
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Code: Select all
[...]
if(m_objects[i]->type == pipe)
{
Pipe pipe = &m_objects[i];
hector->SetSomeFunc(pipe.derivedOnlyFunc());
}
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.
So you haveJS Lemming wrote:Yeah, I know all that stuff. My program works just fine. My problem, which isn't really a problem so much as poor design, is that I can't access values in the derived classes from within a different derived class. I'm asking if there is some sly way of overcoming that, which I doubt but was unsure of, and if not I will simply not utilize polymorphism and instead make separate lists containing the separate stage objects which I know for a fact I can access the variables from.
Sorry for the confusion.
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Yeah, I'm pretty sure it's not gonna work for me. It's not that big of a deal though. The code will just be a bit more cluttered and harder to maintain with all the separate lists.MarauderIIC wrote:So you have
Class A
Class B : public A { int qqq; }
Class C : public A { int getqqq() { return qqq;} }
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
I realized the moment I fell into the fissure that the book would not be destroyed as I had planned.
Code: Select all
class A // placeholder class #1
{
int a;
public:
friend inline int get_a( A object );
};
class B // placeholder class #2
{
int a;
public:
friend inline int get_a( B object );
};
inline int get_a( A object ) // get_a for class A
{
return object.a;
}
inline int get_a( B object ) // get_a for class B
{
return object.a;
}
Code: Select all
class A
{
int a;
friend class B;
};
class B
{
A object; // B can manipulate object's private members because of the friend class declaration
public:
B();
int get_a();
};
B::B( int a )
{
object.a = a;
}
int B::get_a()
{
return object.a;
}
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
I know, but it would be a lot of stuff. Not practical and hard to maintain.qpHalcy0n wrote:You could simply map out the things that the child objects have in common with eachother and store them as protected members of the base class.
Code: Select all
#ifndef STAGEOBJECT_H
#define STAGEOBJECT_H
#include "enum.h"
class stageObject
{
public:
stageObjectType type;
stageObject();
virtual void update()=0;
virtual void draw()=0;
//for objects like hector who need to report it's x position so the proper
// baseX can be set...
virtual float specialReport()=0;
};
#endif // STAGEOBJECT_H
Code: Select all
#ifndef HECTOR_H
#define HECTOR_H
#include "stageobject.h"
class hector: public stageObject
{
public:
float x, y;
hector(int xStart, int yStart);
virtual ~hector();
void update();
void draw();
float specialReport();
};
#endif // HECTOR_H
Code: Select all
#ifndef gyroPipe_H
#define gyroPipe_H
#include "stageobject.h"
class gyroPipe: public stageObject
{
public:
int imageData;
int color; //0=blue, 1=red
bool vertical;
int startPositive; // 0=no, 1=yes
int sliderX, sliderY, length;
float extension;
gyroPipe(int argColor, bool argVertical, int argX, int argY, int argLength, int argImageData);
virtual ~gyroPipe();
void update();
void draw();
float specialReport();
};
#endif // gyroPipe_H
Small girl at the harbor wrote:Look Brandon, that crab's got ham!
Code: Select all
[...]
for(int i = 0; i < m_objects.size(); i++)
if(m_objects[i]->type == HECTOR)
{
hectorIdx = i;
break;
}
for(int i = 0; i < m_objects.size(); i++)
{
if(m_objects[i]->type != HECTOR)
{
if(CheckCollide(m_objects[hectorIdx], m_objects[i]) == true)
//do stuff
}
}
Gyro Sheen wrote:you pour their inventory onto my life
IRC wrote: <sparda> The routine had a stack overflow, sorry.
<sparda> Apparently the stack was full of shit.