• Advertisement
Sign in to follow this  

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

This topic is 3870 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Try switching std::vector<EnemyShip>* to std::vector<EnemyShip*>* [or &] - to see how the definition of the vector can change anything. As far as anything MSVC-specific, I'm useless.

Share this post


Link to post
Share on other sites
Quote:
Original post by Evil Booger
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.


That's because you're using the debug library in the release compile at that point. Did you compile the SDL yourself or are you using a precompiled library? If it's precompiled it may not be compatible with VS2005 for whatever reason; try compiling it with the same settings your project uses (either dll or static, debug or release, your choice, but make sure the lib compiles the same way your project is).

Also try explicitly linking LIBCMTD.LIB in your debug version. And if you don't want to or can't recompile the SDL try release again but with the release library linked instead of the debug one.

Someone had this problem and never reported success a year and a half ago. Here is something to read. Somehow I bet the OP got it fixed and just never came back to say what fixed it. :( More things to try though.

Another example of someone fixing this problem by explicitly recompiling the SDL with VS2005 here.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement