need programming help

Discussions About Anything Civilized, Hacking or Not

Moderators: g3nuin3, SpeedWing, WhiteHat, mezzo

need programming help

Postby LouCypher » Fri Oct 05, 2007 2:24 pm

So I'm trying to recompile a WoW hack with errors included to prevent others from compiling and selling it. I've no intentions of doing that, I just want to understand it better.

I've figured out some of the errors, but since I'm not a programmer I have no idea how to fix the code for four of them. I could really use an example on just one of them and I think I could follow that to fix the others.

This is the function:
Code: Select all
SNode * SZone::AddNode( SNode * Node )
{
   return vNodes.push_back( Node );
}
For which I get an
Code: Select all
error C2440:  'return' : cannot convert from 'void' to 'SNode *'
vNodes is defined in:
Code: Select all
struct SZone
{
   char szName[256];
   std::vector<SPath*> vPaths;
   [b]std::vector<SNode*> vNodes;[/b]

   SZone();
   ~SZone();
   SZone( const char * szName );

   SNode * GetNodeByName( const char * szName );
   SNode * AddNode( SNode * Node );

   SPath * GetPathByName( const char * szName );
   SPath * AddPath( SPath * Path );
};
Please help me.
User avatar
LouCypher
Hackleberry Fin
 
Posts: 27
Joined: Tue Jul 18, 2006 9:30 am

Postby L. Spiro » Fri Oct 05, 2007 3:29 pm

There are 2 ways to fix the error and one way has 2 methods, and the only way to be sure which of these ways are correct is to actually have the code.


No I do not want it; I will give you the most likely solution and see if it works.


One fix is to change the function to this:
Code: Select all
void SZone::AddNode( SNode * Node )
{
   vNodes.push_back( Node );
}

and then you would have to:
Code: Select all
void AddNode( SNode * Node );

in the class declaration.


But that might create a million other errors if the function actually DOES return a value, so the most likely solution is:
Code: Select all
SNode * SZone::AddNode( SNode * Node )
{
   return vNodes.push_back( Node ), Node;
}




This method MIGHT cause some problems later in the program depending on things I wouldn’t know without the source.
I have the solution in case it causes problems but for now try this.


L. Spiro
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan

Postby LouCypher » Fri Oct 05, 2007 4:51 pm

L. Spiro wrote:But that might create a million other errors if the function actually DOES return a value, so the most likely solution is:
Code: Select all
SNode * SZone::AddNode( SNode * Node )
{
   return vNodes.push_back( Node ), Node;
}
Well it definitely got rid of the error, no idea if it will mess up other things. Thank you for that help.

Given that example, I turned this:
Code: Select all
SMap * CWorld::AddMap( const char * sz_Name )
{
   return vMaps.push_back( new SMap( sz_Name ) );
}
into:
Code: Select all
SMap * CWorld::AddMap( const char * sz_Name )
{
   SMap * result = new SMap( sz_Name );
   return vMaps.push_back( result ), result;
}
Which eliminated another C2440 error. Does that look okay?
User avatar
LouCypher
Hackleberry Fin
 
Posts: 27
Joined: Tue Jul 18, 2006 9:30 am

Postby L. Spiro » Fri Oct 05, 2007 5:44 pm

Most likely.


L. Spiro
User avatar
L. Spiro
L. Spiro
 
Posts: 3129
Joined: Mon Jul 17, 2006 10:14 pm
Location: Tokyo, Japan


Return to Social/Unrelated

Who is online

Users browsing this forum: No registered users and 0 guests