Problem with a friend function in a derived class that takes a pointer to a vector as

Started by
12 comments, last by Evil Booger 16 years, 10 months ago
Hi again, I’m working on a small 2d space shooter and I’m not sure what the problem is, but I think its that I have the class type in a vector in the friend declaration in the class: class EnemyShip: public Ship { friend void AI_Formation_One(std::vector<EnemyShip> * e_ship_vec); public:……… The error was: 1>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class EnemyShip & __thiscall std::vector<class EnemyShip,class std::allocator<class EnemyShip> >::operator[](unsigned int)" (??A?$vector@VEnemyShip@@V?$allocator@VEnemyShip@@@std@@@std@@QAEAAVEnemyShip@@I@Z) Ok, I think I gave you enough information. Thank you in advance for helping
Advertisement
Quote:Original post by Evil Booger
Hi again, I’m working on a small 2d space shooter and I’m not sure what the problem is, but I think its that I have the class type in a vector in the friend declaration in the class:

class EnemyShip: public Ship
{
friend void AI_Formation_One(std::vector<EnemyShip> * e_ship_vec);
public:………

The error was:

1>main.obj : error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: class EnemyShip & __thiscall std::vector<class EnemyShip,class std::allocator<class EnemyShip> >::operator[](unsigned int)" (??A?$vector@VEnemyShip@@V?$allocator@VEnemyShip@@@std@@@std@@QAEAAVEnemyShip@@I@Z)

Ok, I think I gave you enough information. Thank you in advance for helping


I'm not sure about this, but perhaps the problem lies elsewhere since it says "in function "public: class EnemyShip..." and your vector is in private. Just a guess, I'm not too familiar with the error messages yet. Good luck!

According to google several others have had the same problem
Maybe this helps
http://www.groupsrv.com/dotnet/post-798072.html
Shakedown, I don't think that is the case, but just in case here's the rest of the class:
class EnemyShip: public Ship
{
friend void AI_Formation_One(std::vector<EnemyShip> * e_ship_vec);
public:
void AI_Attack(int player_pos_x);
void Show();
int shiptype;

//void AI_Dodge();
EnemyShip(int x,int y);
EnemyShip();
//EnemyShip(EnemyShip *eShip);
};

And to explain more what I think it is, I think its illegal to have a friend function in a class with the class as a argument type before the class is defined.
From "Unresolved external symbol" it seems you have to forward declaration the AI_Formation_One function. and don't forget to include stl header file.
Forward Declaration? Are you saying that I need to declare it before I define the class? But then I would have to declare the class too. Ok I'll try it.
pulpfist:

Well according the posts in the page you gave me, the problem was caused because some _DEBUG_ code was left in the release build, but my project's active configuration is debug so it shouldn't mess anything up.


But I do think my problem has something to do with my runtime library because when I change the runtime setting (ex Multi-threaded DLL, Multi-threded Debug DLL) I get different errors.
Its hard to say since I never had that exact problem myself, but the symbol the linker is complaining about is CrtDbgReportW and that smells like a MS debug function.
This thread has some info as well
Do you get rid of the unresolved external errors if you change the code generation option?
Are you linking any code (like dlls or libs) other than your own .h and .cpp files and the standard library ones that'll link automatically through the headers you're including? I had an issue similar to the one you're having before and it turned out to be a lib I was using that had been compiled in release, so I couldn't compile my code in debug and link with it.

Try a release build and see if it works. Or if you are using an external library and have access to the source, compile a debug version and make sure you're using it and not a release one.

If all else fails, since this seems to be a linking issue, you could try creating a new project and adding all your files to it and building (so basically all the project settings go back to defaults). Again, try both debug and release. If only release works, you've got some release build stuff linking in that won't let you compile in debug.
To pulpfist:
When I change my runtime code generation options to a debug option(Multi-threaded Debug DLL (/MDd)), I get the error:
1>mt.exe : general error c101008a: Failed to save the updated manifest to the file ".\Debug\Space Shooter.exe.embed.manifest". The parameter is incorrect.

To Xentropy:
I am using SDL and if I change my active configuration to release I get a ton of unresolved external symbols about various SDL functions.

To everyone:
Thank you so much for staying with me and trying so hard to help some you don’t know.

This topic is closed to new replies.

Advertisement