Quick error help

Started by
4 comments, last by theOcelot 15 years, 4 months ago
I am obviously new to c++ but I dont know how to fix this at all, I don't even know what the problem is. I think its pretty obvious what im trying to do. If effectname == NULL , then bool HasEffect = False. These are my errors 1>c:\documents and settings\hp_administrator\desktop\source\chapter 10\engine\effect.cpp(14) : error C2659: '=' : function as left operand 1>c:\documents and settings\hp_administrator\desktop\source\chapter 10\engine\effect.cpp(17) : error C2659: '=' : function as left operand Here is the H file.
class Effect : public Resource< Effect >
{
public:
	Effect(char* realname, char *effectname);
	
	bool HasEffect();
	virtual ~Effect();
	void Render();

private:
	//other code not necessary to show

};


Source
Effect::Effect( char * realname, char *effectname) : Resource< Effect >( realname, effectname )
{
if(effectname == NULL)
{
	effectname = "./Assets/default.fx";
	HasEffect = false;
}
else{
	HasEffect = true;
}
// more code below not necessary to show



Advertisement
The error tells you exactly what the problem is, HasEffect is a function, and you put it on the left hand side of an =. Perhaps you meant to declare HasEffect as a variable and not a function?
yeah I want it as a variable, but I thought i had to put it in public, so I could access it outside of the class
Quote:HasEffect


is a member function. You cannot assign to that.

Also, as a matter of style:
Effect::Effect( const char * realname, const char *effectname)   : Resource< Effect >( realname, effectname ) {}template < class T >class Resource {public:  bool HasEffect() const {    return effectName != NULL;  }private:  const char * effectname;};


No need to state same information twice. If effectname is NULL, Resource does not have an effect. So effectname is sufficient criteria, and also justifies the use of getter function.

And if you do need to use string literals, make sure to pass them as const char *, as to avoid the memory management issues with dynamic allocations.
Ok, while I appreciate that example you gave me, I am not sure if it will match with the oo design I am using, or at least I don't know how to do it. I will ask this in a different way. I am trying to call on m_effect->Render, in an entirely different class. My app crashes though, because I don't have effects specified. Basically what I am trying to accomplish, is that if HasEffect == true, then Render. The problem is that I don't know how to call on HasEffect from a different class when its just a variable. Am I being clear?
Clear as mud.

You may want to make a protected/private member variable, and then a public function to access it.

This topic is closed to new replies.

Advertisement