Sign in to follow this  

Quick error help

This topic is 3292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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



Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites

This topic is 3292 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this