   [C++]Unresolved external symbol error help!
  Ok, Im getting this error when I try to run my program...1>OS.obj : error LNK2019: unresolved external symbol "void __cdecl getchoice(char * const)" (?getchoice@@YAXQAD@Z) referenced in function "void __cdecl mainpage(void)" (?mainpage@@YAXXZ)1>C:\Documents and Settings\(me)\My Documents\C++PROJECTS\OS\Debug\OS.exe : fatal error LNK1120: 1 unresolved externalsI dont know what the problem is...here is my 'mainpage' function...void mainpage(){char choice[50];void getchoice(char choice[]);for( ; ; ){system("cls");cout<<"Type 'help' for a list of commands\n";gets_s(choice);getchoice(choice);   if(choice=='exit'){break;} }_getch();}and my other functions...void getchoice(char choice[50]){char help[5]="help";char logoff[7]="logoff";char calc[5]="calc";bool x;void help();void logoff();void calc();x=strcmp(choice, 'help');if(x){help();}elsex=strcmp(choice, 'logoff');if(x){logoff();};elsex=strcmp(choice, 'calc');if(x){calc();};}void help(){cout<<"\n\nThe commands you can use are:"<<"\n'help'\tShow Commands"<<"\n'logoff'\tLog out of the machine"<<"\n'calc'\tUse the calculator\n";}void logoff(){cout<<"logging off";}void calc(){cout<<"using calculator";}Please help if you can   
  In void mainpaige(), you're trying to declare the function void getchoice(char choice[]).  You can't declare functions inside of other functions.  What you want to do is declare void getchoice(char choice[]) at the global scope (outside of and before void mainpaige()).  I also highly suggest you look at std::string.  char* are messy and error prone.  std::string rules.[edit]Corrected my post.  Thanks Zahlman.[Edited by - MikeTacular on May 15, 2009 12:02:37 AM];  You have several issues. In fact I'm honestly surprised that compiles at all much less almost link correctly. First, you should strongly consider using std::string instead of char arrays. You can't compare char arrays like this:choice=='exit'for two reasons. 1)Using == with char arrays doesn't actually compare choice with the string literal 'exit' and 2)'exit' isn't even really a string but a 'wide' character literal. You would need to use double quotes to get a string literal. You use strcmp elsewhere so either use that or, better, use std::string.In addition to that problem, doingvoid mainpage(){...void getchoice(char choice[]);doesn't do what you think it does. It doesn't CALL a function, it DECLARES one.  You call it correctly later on. In any case, you shouldn't be hardcoding arrays like that. make the function something more likevoid getchoice(char * choice, size_t size){There's probably other issues as well but that should get you started.   ;  Yeah i know about the exit part... i know you cant compare with ==... idk what i was thinking.. i put that in as i was making the topic.another thing.. i dont really understand the std::string. it never seems to work for me... idk...   ;Quote:Original post by MikeTacularIn void mainpaige(), you're trying to declare the function void getchoice(char choice[]).  You can't declare functions inside of other functions.Unfortunately, yes, you can.OP:The problem is that the declaration is of a slightly different type (a function named getchoice which accepts a pointer to character - yes, even though you wrote "[]" - and returns void; versus a function named getchoice which accepts an array of 50 characters and returns void).It's possible to pass the array to a function which accepts the pointer, but not the other way around. When the compiler sees your call "getchoice(choice);", it interprets that as a call to the function which accepts the pointer, because that declaration is in a tighter scope, and because it's possible to call such a function with the given input.Then when the linker tries to resolve the call, it sees that the version of the function accepting a pointer is not defined.(By the way, you do realize that you're basically writing C code here, and that things are done completely differently in modern C++, yes? In particular, do check out the links MikeTacular gave you.)Quote:What you want to do is declare void getchoice(char choice[]) at the global scope (outside of and before void mainpage()).Except it would need to be (char choice[50]).Alternatively, you could just put the getchoice function before the mainpage function in the source file. Then it is already declared (a definition implies a declaration) by the time the compiler tries to make sense of mainpage().   ;Quote:Original post by meb111another thing.. i dont really understand the std::string. it never seems to work for me... idk...Here is all of the source you posted, redone to use std::string properly (and just to be a little more modern in general). Please study it carefully. It's actually much easier to use than what you've been doing, as writing things "the obvious way" is normally correct.void logoff() {std::cout << "logging off" << std::flush;}void calc() {std::cout << "using calculator" << std::flush;}void help() {// When you format code, please don't assume that tabs are any// specific size. Please examine my whitespace carefully.std::cout << "\n\nThe commands you can use are:"<< "\n'help'\tShow Commands"<< "\n'logoff'\tLog out of the machine"<< "\n'calc'\tUse the calculator\n";}void getchoice(const std::string& choice) {// You don't need any temporary variables here. Simplify.if (choice == "help") { help(); }else if (choice == "logoff") { logoff(); }else if (choice == "calc") { calc(); }}void mainpage(){std::string choice;while (true) {system("cls");std::cout << "Type 'help' for a list of commands\n";std::getline(std::cin, choice);if (choice == "exit") { break; }getchoice(choice); }// don't artificially pause programs at the end, please.}EDIT: Also, this belongs in For Beginners. Moved.   ;Quote:Original post by ZahlmanQuote:Original post by MikeTacularIn void mainpaige(), you're trying to declare the function void getchoice(char choice[]).  You can't declare functions inside of other functions.Unfortunately, yes, you can.Wow... epic fail me. [embarrass] Thank you for the correction.   ;Quote:Original post by ZahlmanQuote:What you want to do is declare void getchoice(char choice[]) at the global scope (outside of and before void mainpage()).Except it would need to be (char choice[50]).I'm pretty sure the dimensions of arrays in parameter lists are ignored. The following signatures are equivalent:// You can pass arrays of any size to any of these functions:void fun(char a[]);void fun(char a[50]);void fun(char *a);Now when you pass arrays by reference, it's a different story:// You can only pass arrays of size 50 to this function:void fun(char (&a)[50]);But of course none of these details really matter -- just use std::string and be done with it.   ;Quote:Original post by MikeTacularQuote:Original post by ZahlmanQuote:Original post by MikeTacularYou can't declare functions inside of other functions.Unfortunately, yes, you can.Wow... epic fail me. [embarrass] Thank you for the correction.And this is the standard "use case":int main(){    Player player();    Game game(player);    game.start();}Can you spot the mistake? ;)   ;Quote:Original post by DevFredCan you spot the mistake? ;)Which are functions and which are classes?  The compiler thinks Player player(); is a function forward declaration, right?  Which you could solve by removing the unnecessary parentheses, correct?  As far as Game game(player); goes, I'm not sure.  Since you pass a parameter in the constructor rather than just a type, it interprets it as a Game constructor and not as a function forward declaration, right?  I want to make sure I really learn this right so I don't have another embarrassing shenanigan like that again [smile]   