Identifier Not Found Error on Function Call

Identifier not found error on function call

Add this line before main function:

void swapCase (char* name);

int main()
{
...
swapCase(name); // swapCase prototype should be known at this point
...
}

This is called forward declaration: compiler needs to know function prototype when function call is compiled.

Identifier not found error on function call Visual c++

The problem is that you are using (calling) some of your functions before you define or declare them (GiveItem and RemovetItem in LevelObject::Interact). However, you can't define those functions before you have defined/declared the Player structure!

To get round this problem, you can provide function prototypes - these are 'empty' declarations of the functions, which simply specify their 'form' (or signatures). Place these near the top of your code (it's good practice to do so for all functions, even if these pre-declaraions aren't strictly necessary). Here's a typical way to do this:

// -----------------------------------------Prototypes------------------------------------------//

void RemoveItem(string ItemName2);
bool ItemCheck(string ItemName1);
void TakeItem(string ItemName0);
void GiveItem(string ItemName);
void ColorText(std::string Text0, int Color, bool endl);
void inventory();

//-------------------------------------------Virables-------------------------------------------//

You also have a problem in your ItemCheck function, where your line bool T_F = true; inside the for loop declares a new variable, T_F that 'hides' (and replaces) the variable with the same name declared at function-level scope. Remove the bool from this line, so that you are setting that function-level variable's value:

bool ItemCheck(string ItemName1)
{
bool T_F = false;
for (int i = 0; i < 20;) {
if (player.inv[i].name == ItemName1) {
T_F = true;// "bool = T_F = true"; hides (replaces) the other T_F variable!
break;
}
i++;
}
return T_F;
}

Also, for good coding guidelines, please read this: Why is "using namespace std;" considered bad practice?.

Identifier not found when calling a function under a function

Just move these lines to the beginning, before any other function:

// function return AM/PM respect to hour of time
string GetAM_PM(int twelve_hours) {

return twelve_hours >= 12 ? "PM" : "AM";
}

It is not this case, but if you end up with circular dependency, try to declare the methods in a .h or forward declare the methods in the code.

Identifier not found error?

This is a great example of declarations, prototypes and definitions, that are something that you need to know.

Functions prototypes are a way to declare the function structure without his body, for example:

int my_function(int arg1, int arg2);

In fact, in function prototypes you don't even need to put the arguments name, just their type:

int my_function(int, int);

As the compilation process goes from top to down, when you have this code

// function a definition
int function_a()
{
int some_variable = function_b();
}

// function b definition
int function_b()
{
return 20;
}

the compiler will know nothing about function_b() when you call her in function_a(), so, you must either reorder your code like this

// function b definition
int function_b()
{
return 20;
}

// function a definition
int function_a()
{
// now the compiler knows how function_b() works, or, at least, what arguments she need
int some_variable = function_b();
}

or use prototypes to preserve your code organization, like this

// function b prototype
int function_b();

// function a definition
int function_a()
{
int some_variable = function_b();
}

// function b definition
int function_b()
{
return 20;
}

so, now, the compiler knows that there's a "function_b" that exists, and know what her parameters and return value type are (in this case, there's no parameters and the return type is int)

For order, you'll usually put the function prototype in the header file (.h) and the definition in the code file (.c/cpp)

In your example, inside of the main function you are calling the DealingHandler and EndProgram functions, but they're defined later and that's why you get an error. So, using functions prototypes you can fix it easily, putting

/* this can be
int DealingHandler(int);
because function prototypes doesn't need argument's name, just their types */
int DealingHandler(int HowManyDealed);
void EndProgram();

upon the main() function, or, better, below this line

using namespace std;

After creating a method in c++ when calling it i'm getting error identifier not found

You said you added the method to the bottom of the cpp file.

You have to declare or define identifiers to use before using them, so try adding prototype declaration void SaveVideoToFile(int hr); before where the function is used.

logIn': identifier not found

The problem is that you use logIn() before it is declared. You can solve this by adding a forward declaration prior to mainMenu():

void logIn();

void mainMenu() {
...
}

void logIn() {
...
}


Related Topics



Leave a reply



Submit