Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ozzo

type modifiers problem

This topic is 5245 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

getting this error during compile and don't really know why.
    
error C2065: 'Accumulator' : undeclared identifier
error C2373: 'Accumulator' : redefinition; different type modifiers
i mean it is declared and i don't see whats wrong with the type. here are the functions, all of which are in main.cpp
   
float Accumulator( const char theOperator, const float theOperand = 0)
{
	static float myAccumulator = 0; // initialised to 0 when program starts

	
	switch (theOperator)
	{
	case '+':
			myAccumulator = myAccumulator + theOperand;
			Tape(theOperator, theOperand);
			break;

	case '-':
			myAccumulator = myAccumulator - theOperand;
			Tape(theOperator, theOperand);
			break;

	case '*':
			myAccumulator = myAccumulator * theOperand;
			Tape(theOperator, theOperand);
			break;

	case '/':
			myAccumulator = myAccumulator / theOperand;
			break;

	case '@':
			myAccumulator = theOperand;
			Tape(theOperator, theOperand);
			break;

	case '=':
			cout << /*endl*/ myAccumulator << endl;
			break;

	case '?': // display the tape

			Tape(theOperator, theOperand);
			break;

//	case '.':

//			break;


	default:
		throw
			runtime_error
			("Error - Invalid Operator");
	}

	return myAccumulator;
}
   
bool TestOK( const char theOperator, const float theOperand, const float theExpectedResult )
{
	float Result = Accumulator(theOperator, theOperand);

	if (Result == theExpectedResult)
	{
		cout << theOperator << theOperand << " . succeeded." << endl;
		return true;
	}
	else
	{
		cout << theOperator << theOperand << " .failed. " <<
		"Expected " << theExpectedResult << ", got " << Result << endl;

		return false;
	}
}
when i remove the TestOK function, it will say "undeclared identifier" on the next occurence of Accumulator(). 2nd Question. If u make an array to record scores and u delete the entire thing to remake the array to hold more. Are u ment to see something like "|,5690000" on the number of scores uve entered so far when u view the entries AFTER uve remade the arrays? [edited by - ozzo on February 8, 2004 8:00:52 AM]

Share this post


Link to post
Share on other sites
Advertisement
1st question: Make sure that you have a function declaration or the function above the caller in the source file before you try to call it.

void f();
void g();

void f(){ g(); /* do stuff */ }
void g(){ /* do stuff */ }

2nd question: Frankly, I don''t quite understand it.

Share this post


Link to post
Share on other sites
"If u make an array to record scores and u delete the entire thing to remake the array to hold more. Are u ment to see something like "|,5690000" on the number of scores uve entered so far when u view the entries AFTER uve remade the arrays?"

Either:

a) use a vector and forget about it. think of it as an array they grows for you:

std::vector scores;
scores[0] = 7666;

b) copy your old array into the new one BEFORE deleting it:

int* tmp = new int[10000];
memset(tmp, 0, sizeof(tmp));
// make sure scores is smaller!
memcpy(scores, tmp, sizeof(scores));
delete[] scores;
scores = tmp;

Obviously, option a is the easiest/safest. This is all out of my head, but it should be enough to give you an idea.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!