Thread: Problem with class function

  1. #1
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320

    Question Problem with class function

    Im not really sure why im getting this probably some type o.

    testingserv.obj : error LNK2001: unresolved external symbol "public: bool __thiscall Character::InUse(void)" (?InUse@Character@@QAE_NXZ)
    Debug/testingserv.exe : fatal error LNK1120: 1 unresolved externals
    Code:
    //from header file
    public:
    bool InUse();
    
    private:
    int id;
    //from the cpp
    bool Character::InUse()
    {
    	if(id == -1)  // if !in use
    	{	
    		return false;
    	}
    	return true;
    }
    
    //my call thats causing this
    int OpenSpot()  // defined at the start of the program
    {
    	for(int x = 0; x<50;x++)
    	{
    		if(!Players[x].InUse())  //Players is a array of 50 Characters 
    		{
    			return x;  // found a open spot
    		}
    	}
    	return -1;  //no open spots send error to client
    }
    Does ne1 see my problem?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    i suggest using the void keyword
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    That wouldn't make a differance and I found the error just needed to recompile all the code for some reason it wasn't compiling every little bit of code.

    Microsoft 1

    Me 0

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    it was the only thing i saw...it may have made a difference in some non-standard compilers.


    don't feel bad. microsoft has scored many more than that on me
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  5. #5
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903

    Cool

    I would suggest maybe taking a different approach to making this boolean test..

    The call to Players[x].InUse() is element specific in your array of classes... I'm thinking you might want to give your InUse( ) a more global scope.. that will iterate through all the elements of your class array.. and make the true/false determination you are looking for.

    1) Declare another object of your class.. that is not an array.

    2) Create an object of this class. i.e. MyClass object;

    3) reference your IsUse( ) function using the non-arrayed object. object.InUse( )

    4) change the InUse( ) function definition.. to iterate through your array of classes.. to make the true/false determination(s) you are looking for.



    I hope this makes some sort of sense. I think I drank too much beer at work again. But it's all good. Basically.. I think what I'm trying to get at.. is instead of having like 50 possible ways to call InUse( ) you could just call it once using a non-arrayed class object... and I think your linker might like this method as well.
    Last edited by The Brain; 10-22-2004 at 07:14 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  6. #6
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Also.. i think if you want to keep your array idea then I think you need to specify the element for 'id'

    Code:
    if(id == -1)

    I think should be:
    Code:
    if(Players[x].id == -1)

    I think this will keep 'id' and 'IsUsed( )' element specfic in scope. (id and IsUsed( ) will have to be in the same element)
    Last edited by The Brain; 10-22-2004 at 07:20 AM.
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  7. #7
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    I think should be:
    Code:
    if(Players[x].id == -1)

    I think this will keep 'id' and 'IsUsed( )' element specfic in scope. (id and IsUsed( ) will have to be in the same element)

    Umm id is private therefore i can not referance it directly thus the function and if i were to make it public thats just destroying the whole reasoning of classes. Also the array is ment to store 50 characters playing on the server not just one character NPCs have a seperate class.
    Last edited by ~Kyo~; 10-22-2004 at 01:57 PM.

  8. #8
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    I suspect the error message is because the linker can't find InUse(). Make sure the header file containing InUse() is in the same directory as your exe file and that you have included the header file in the list of includes in the program itself.

    If that doesn't solve it, and if they're not 14 pages long, then please post the header file containing InUse(), the cpp file containing InUse() and the declaration of Players.

  9. #9
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    Umm id is private....
    Yais.. ID is private.. but if you look closely.. you give IsUsed( ) permission to access private class member variables...


    Code:
    bool Character::InUse(Character* Players[])
    {
    	if(Players[x].id == -1)  // if !in use
    	{	
    		return false;
    	}
    	return true;
    }
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  10. #10
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    Quote Originally Posted by The Brain
    Yais.. ID is private.. but if you look closely.. you give IsUsed( ) permission to access private class member variables...


    Code:
    bool Character::InUse(Character* Players[])
    {
    	if(Players[x].id == -1)  // if !in use
    	{	
    		return false;
    	}
    	return true;
    }

    no no I want the subscript of the first unused spot i dont want to get all of emm right away that would mean 50 iterations each time and i only want there to be as many as needed. Also x is undefined in that function. I solved the problem no need to debate it.

  11. #11
    VA National Guard The Brain's Avatar
    Join Date
    May 2004
    Location
    Manassas, VA USA
    Posts
    903
    replace [x] with whatever
    • "Problem Solving C++, The Object of Programming" -Walter Savitch
    • "Data Structures and Other Objects using C++" -Walter Savitch
    • "Assembly Language for Intel-Based Computers" -Kip Irvine
    • "Programming Windows, 5th edition" -Charles Petzold
    • "Visual C++ MFC Programming by Example" -John E. Swanke
    • "Network Programming Windows" -Jones/Ohlund
    • "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
    • "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel

  12. #12
    Registered User ~Kyo~'s Avatar
    Join Date
    Jun 2004
    Posts
    320
    go reread my 2rd post (3rd in thread) also you way uses to many iterations yer doing more work than whats needed wasting time and when dealing with sockets and such time is valuable. reading all 50 instantiations is not a good way to do this when i may only need 5. Would a mod lock this thread for me?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. deriving classes
    By l2u in forum C++ Programming
    Replies: 12
    Last Post: 01-15-2007, 05:01 PM
  3. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM