CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Posts
    27

    error LNK2019 unresolved external symbol

    I keep getting these error messages:

    "error LNK2019: unresolved external symbol "void __cdecl MainPhase(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > *)" (?MainPhase@@YAXPAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z) referenced in function _main"

    "error LNK2019: unresolved external symbol "void __cdecl DrawForKaiba(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > *)" (?DrawForKaiba@@YAXPAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z) referenced in function _main"

    and

    " error LNK2019: unresolved external symbol "void __cdecl Beginning(class std::vector<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > > *)" (?Beginning@@YAXPAV?$vector@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@@Z) referenced in function _main"

    the code is below




    Code:
    
    #include <stdlib.h>
    #include <windows.h>
    #include <ctime>
    #include <cstdlib>
    #include <iostream>
    #include <vector>
    using namespace std;
    
    //srand(time(0));
    
    vector<string> Hand;
    vector<string>::iterator it;
    
    vector<string> Field;
    vector<string>::iterator Ft;
    
    void Beginning(vector<string> *Hand);
    void DrawForKaiba(vector<string> *Hand);
    void MainPhase(vector<string> *Hand);
    void BattlePhase();
    int MainHand;
    int CardSlot;
    int Decision;
    
    
    int main()
    {
    	srand(time(0));
    
    Beginning(&Hand);
    DrawForKaiba(&Hand);
    MainPhase(&Hand);
    BattlePhase();
    
    
    cout<< "\n"<<"GAME OVER"<<endl;
    
    return 0;
    } 
    
    
    
    void Beginning(vector<string> &Hand)
    {
    for (int i=1; i<6; i++)
    	{
    		DrawForKaiba(&Hand);
    	}
    }
    
    
    void DrawForKaiba(vector<string> &Hand)
    {
    
    int DrawKaiba = rand() % 40 + 1;
    cout<<"Random number is: "<<DrawKaiba<<" "<<endl;
    
    switch (DrawKaiba)
    {
    case 1:
    case 2:
    case 3:
    	cout<<"BLUE EYES WHITE DRAGON"<<endl;
    	Hand.push_back("BLUE EYES WHITE DRAGON");
    	break;
    case 4:
    	cout<<"Vorse Raider"<<endl;
    	Hand.push_back("VORSE RAIDER");
    	break;
    case 5:
    	cout<<"BLADE KNIGHT"<<endl;
    	Hand.push_back("BLADE KNIGHT");
    	break;
    case 6:
    	cout<<"KAISER SEA HORSE"<<endl;
    	Hand.push_back("KAISER SEA HORSE");
    	break;
    case 7:
    	cout<<"LORD OF DRAGONS"<<endl;
    	Hand.push_back("LORD OF DRAGONS");
    	break;
    case 8:
    case 9:
    case 10:
    	cout<<"THUNDER DRAGON"<<endl;
    	Hand.push_back("THUNDER DRAGON");
    	break;
    case 11:
    	cout<<"CYBER JAR"<<endl;
    	Hand.push_back("CYBER JAR");
    	break;
    case 12:
    	cout<<"SPEAR DRAGON"<<endl;
    	Hand.push_back("SPEAR DRAGON");
    	break;
    case 13:
    	cout<<"TWIN HEADED BEHEMOTH"<<endl;
    	Hand.push_back("TWIN HEADED BEHEMOTH");
    	break;
    case 14:
    	cout<<"X CANNON HEAD"<<endl;
    	Hand.push_back("X CANNON HEAD");
    	break;
    case 15:
    	cout<<"Y DRAGON HEAD"<<endl;
    	Hand.push_back("Y DRAGON HEAD");
    	break;
    case 16:
    	cout<<"Z HEAD TANK"<<endl;
    	Hand.push_back("Z HEAD TANK");
    	break;
    case 17:
    	cout<<"VAMPIRE LORD"<<endl;
    	Hand.push_back("VAMPIRE LORD");
    	break;
    case 18:
    	cout<<"SPIRIT RYU"<<endl;
    	Hand.push_back("SPIRIT RYU");
    	break;
    case 19:
    	cout<<"POSSESSED DARK SOUL"<<endl;
    	Hand.push_back("POSSESSED DARK SOUL");
    	break;
    case 20:
    	cout<<"LA JINN THE MYSTICAL GENIE OF THE LAMP"<<endl;
    	Hand.push_back("LA JINN THE MYSTICAL GENIE OF THE LAMP");
    	break;
    case 21:
    	cout<<"DIFFERENT DIMENSION DRAGON"<<endl;
    	Hand.push_back("DIFFERENT DIMENSION DRAGON");
    	break;
    case 22:
    case 23:
    case 24:
    	cout<<"GIANT GERM"<<endl;
    	Hand.push_back("GIANT GERM");
    	break;
    case 25:
    	cout<<"SHRINK"<<endl;
    	Hand.push_back("SHRINK");
    	break;
    case 26:
    	cout<<"HEAVY STORM"<<endl;
    	Hand.push_back("HEAVY STORM");
    	break;
    case 27:
    	cout<<"MONSTER REBORN"<<endl;
    	Hand.push_back("MONSTER REBORN");
    	break;
    case 28:
    	cout<<"POLYMERIZATION"<<endl;
    	Hand.push_back("POLYMERIZATION");
    	break;
    case 29:
    	cout<<"POT OF GREED"<<endl;
    	Hand.push_back("POT OF GREED");
    	break;
    case 30:
    	cout<<"FLUTE OF SUMMONING DRAGON"<<endl;
    	Hand.push_back("FLUTE OF SUMMONING DRAGON");
    	break;
    case 31:
    	cout<<"COST DOWN"<<endl;
    	Hand.push_back("COST DOWN");
    	break;
    case 32:
    	cout<<"ENEMY CONTROLLER"<<endl;
    	Hand.push_back("ENEMY CONTROLLER");
    	break;
    case 33:
    	cout<<"SILENT DOOM"<<endl;
    	Hand.push_back("SILENT DOOM");
    	break;
    case 34:
    	cout<<"SOUL EXCHANGE"<<endl;
    	Hand.push_back("SOUL EXCHANGE");
    	break;
    case 35:
    	cout<<"CRUSH CARD"<<endl;
    	Hand.push_back("CRUSH CARD");
    	break;
    case 36:
    	cout<<"VIRUS CANNON"<<endl;
    	Hand.push_back("VIRUS CANNON");
    	break;
    case 37:
    	cout<<"RING OF DESTRUCTION"<<endl;
    	Hand.push_back("RING OF DESTRUCTION");
    	break;
    case 38:
    	cout<<"DRAGON'S RAGE"<<endl;
    	Hand.push_back("DRAGON'S RAGE");
    	break;
    case 39:
    	cout<<"FIEND'S SANCTUARY"<<endl;
    	Hand.push_back("FIEND'S SANCTUARY");
    	break;
    case 40:
    	cout<<"INTERDIMENSIONAL MATTER TRANSPORTER"<<endl;
    	Hand.push_back("INTERDIMENSIONAL MATTER TRANSPORTER");
    	break;
    
    
    }
    
    }//DrawforKaiba
    
    
    
    
    void MainPhase(vector<string> &Hand)
    {
    	while(1)//so the while loop NEVER breaks unless you have a 'break' later on
    	{
    	cout<<"Would you like to end the Main Phase? (Yes-'1'  No-'0')"<<endl;
    	cin>>Decision;
    		if (Decision==1)
    		{
    			break;
    		}
    
    		cout<<"Your hand contains: "<<endl;
    		//for (it=Hand.begin(); it<Hand.end(); it++)
    		//{
    		//	cout<<"   qw "<<*it<<endl;
    		//}
    		cout<<"Which card in your hand do you wish to play? (if none, press '0')"<<endl;
    		cin>>MainHand;
    		cout<<"Where do you want to place this card? "<<endl;
    		cin>>CardSlot;
    		switch (CardSlot)
    			{
    			case 1:
    				cout<<"The card is played in the slot 1"<<endl;
    			case 2:
    				cout<<"The card is played in the slot 2"<<endl;
    			case 3:
    				cout<<"The card is played in the slot 3"<<endl;
    			case 4:
    				cout<<"The card is played in the slot 4"<<endl;
    			case 5:
    				cout<<"The card is played in the slot 5"<<endl;
    			case 6:
    				cout<<"The card is played in the slot 6"<<endl;
    			case 7:
    				cout<<"The card is played in the slot 7"<<endl;
    			case 8:
    				cout<<"The card is played in the slot 8"<<endl;
    			case 9:
    				cout<<"The card is played in the slot 9"<<endl;
    			case 10:
    				cout<<"The card is played in the slot 10"<<endl;
    			case 11:
    				cout<<"The card is discarded to the Graveyard"<<endl;
    			}
    
    
        }// end of while(1)
    
    }
    
    
    
    void BattlePhase()
    {
    	while(1)//so the while loop NEVER breaks unless you have a 'break' later on
    	{
    	cout<<"Would you like to end the Battle Phase? (Yes-'1'  No-'0')"<<endl;
    	cin>>Decision;
    		if (Decision==1)
    		{
    			break;
    		}
    
    //		cout<<"Your Field contains: "<<endl;
    //		for (Ft=Field.begin(); Ft<Field.end();Ft++)
    //		{
    //			cout<<" "<<*Ft;
    //		}
    	//	cout<<"Which card on your field do you wish to play? (if none, press '0')"
    	//	cin>>Ft;
    	//	cout<<"My "<<Field[Ft]<<" ATTACKS! "<<endl;
        }// end of while(1)
    
    }

  2. #2
    Join Date
    Jul 2008
    Location
    Croatia
    Posts
    52

    Re: error LNK2019 unresolved external symbol

    You declared functions with
    Code:
    void Beginning(vector<string> *Hand);
    void DrawForKaiba(vector<string> *Hand);
    void MainPhase(vector<string> *Hand);
    but defined them with:
    Code:
    void Beginning(vector<string> &Hand)
    void DrawForKaiba(vector<string> &Hand)
    void MainPhase(vector<string> &Hand)
    Compiler is unable to find function you declared. You are declaring function with pointer as an argument and defined it as a reference.
    Last edited by Borg_ri; October 16th, 2011 at 12:58 PM.

  3. #3
    Join Date
    Nov 2009
    Posts
    27

    Re: error LNK2019 unresolved external symbol

    when I changed the declarations so that I declare the functions with reference as an argument instead, I get these error messages

    Code:
    error C2664: 'Beginning' : cannot convert parameter 1 from 'std::vector<_Ty> *' to 'std::vector<_Ty> &'with
              [
                  _Ty=std::string
              ]
    
     error C2664: 'DrawForKaiba' : cannot convert parameter 1 from 'std::vector<_Ty> *' to 'std::vector<_Ty> &'
              with
              [
                  _Ty=std::string
              ]
     error C2664: 'MainPhase' : cannot convert parameter 1 from 'std::vector<_Ty> *' to 'std::vector<_Ty> &'
              with
              [
                  _Ty=std::string
              ]
     error C2664: 'DrawForKaiba' : cannot convert parameter 1 from 'std::vector<_Ty> *' to 'std::vector<_Ty> &'
              with
              [
                  _Ty=std::string
              ]

  4. #4
    Join Date
    Jul 2008
    Location
    Croatia
    Posts
    52

    Re: error LNK2019 unresolved external symbol

    Now you are incorrectly calling functions.

    Code:
    Beginning(&Hand);
    DrawForKaiba(&Hand);
    MainPhase(&Hand);
    You are giving functions pointer to Hand, and functions take a reference. Delete the "&" in front of Hand.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured