i was just wondering why can't i point something to void. without getting any errors
like for example

class cs_PureFunction
{
public:
	virtual void DoSomething() = 0;
	virtual bool CheckThings() = 0;
};

class cs_EnableOverrideAction: public cs_PureFunction
{
public:
	virtual void DoSomething() { puts("Test123"); }
	
	virtual bool CheckThings()
	{
		if(cin.get())
			return 1;
		return 0;
	}
};


int main(int argc, TCHAR **argv[], ...)
{
	cs_EnableOverrideAction* enableit;

	return enableit->CheckThings();
}

i know if i did

EnableOverrideAction enableit

i wouldn't get a error and i know that.

But this weird error

-		enableit	0xcccccccc	cs_EnableOverrideAction *
-		cs_PureFunction	{...}	cs_PureFunction
		__vfptr	CXX0030: Error: expression cannot be evaluated

i usually only get it if im declaring a integer with the -> so how come i cant call a void or Boolean

Recommended Answers

All 5 Replies

The problem is that you never create a cs_EnableOverrideAction object in main.
What you create in main is just an  uninitialized  pointer  that could point  to  anything.

This will work fine -> cs_EnableOverrideAction * enableit = new cs_EnableOverrideAction; This would also work find   ->   cs_PureFunction * enableit = new cs_EnableOverrideAction; And, of course, if you want to be nice to your OS, you should delete enableit; when you're done with it.

EDIT: Also, in such cases, it's good to make the destructor of your base class virtual, too.

The problem is that you never create a cs_EnableOverrideAction object in main.
What you create in main is just an  uninitialized  pointer  that could point  to  anything.

This will work fine -> cs_EnableOverrideAction * enableit = new cs_EnableOverrideAction; This would also work find   ->   cs_PureFunction * enableit = new cs_EnableOverrideAction; And, of course, if you want to be nice to your OS, you should delete enableit; when you're done with it.

EDIT: Also, in such cases, it's good to make the destructor of your base class virtual, too.

Wow, thanks man. But i dont get it why did i have to put new before and the point is and don't really understand what 'new' does.. I've searched explanations and i still understand it.
And the thing is i've done these things before without getting any error for example: CMyClass and CAnotherClass

class CMyClass
{
public:
   CAnotherClass * m_pAnotherClass;
};

Now if i do so i get an error.. But thanks for the reply i really appreciate it

btw; i'm using visual studio express 2010

-prosammer

Ok right now i've fixed everything ty.

examples:

class CEntity
{
public:

	virtual	int	GetPlayersHealth() = 0;
	virtual float GetPlayerLight() = 0;
	virtual int	GetMaxEntities( int maxents ) = 0;
	virtual bool GetUsersToPress() = 0;
	virtual void IncreasePlayerInfo( int health, float lightness ) = 0;
	virtual void GetPlayerInfo() = 0;
	virtual void Print( const char *fmt, ... ) = 0;

	virtual ~CEntity( void ) { };
};
class CIEntity: public CEntity
{
public:

	CIEntity( int health, float light );

	virtual	int	GetPlayersHealth();
	virtual float GetPlayerLight();
	virtual int	GetMaxEntities( int maxents );
	virtual bool GetUsersToPress();
	virtual void IncreasePlayerInfo( int health, float lightness );
	virtual void GetPlayerInfo();
	virtual void Print( const char *fmt, ... );

	virtual ~CIEntity( void ) { }

private:
	int	m_Health;
	float m_Light;
};
int health = g_pIClientEntity->GetPlayersHealth();
	float lightn = g_pIClientEntity->GetPlayerLight();

	g_pIClientEntity->Print( "hello g_pIClientEntity" );
	g_pIClientEntity->IncreasePlayerInfo(400, 100);
	g_pIClientEntity->GetPlayerInfo();
	g_pIClientEntity->Print( "g_pIClientEntity->GetPlayersHealth(): %d", health);
	g_pIClientEntity->Print( "g_pIClientEntity->GetPlayerLight(): %f", lightn);

	g_pIClientEntity->GetUsersToPress();
	delete g_pIClientEntity;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.