Page 1 of 1

need programming help

PostPosted: Fri Oct 05, 2007 2:24 pm
by LouCypher
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.

PostPosted: Fri Oct 05, 2007 3:29 pm
by L. Spiro
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

PostPosted: Fri Oct 05, 2007 4:51 pm
by LouCypher
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?

PostPosted: Fri Oct 05, 2007 5:44 pm
by L. Spiro
Most likely.


L. Spiro