Jump to content
  • Advertisement
Sign in to follow this  
Evil Booger

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

This topic is 4047 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!