Overload issue

This is a discussion on Overload issue within the C++ Programming forums, part of the General Programming Boards category; I am playing with this code to see if I can get to work so far so good but I ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    10

    Overload issue

    I am playing with this code to see if I can get to work so far so good but I was curious what does this error message mean:

    overloaded function differs only by return type from 'char *itoa(int,char *,int)'

    it is within this code:
    Code:
    void itoa( int32 num, int8  *alpha, int32 radix )
    {
    	if( radix == 10 )
    	{
    		sprintf(alpha, "%i", num);
    	}
    	else if( radix == 16 )
    	{
    		sprintf(alpha, "%X", num);
    	}
    }
    
    int8 *oldModString(int32 modifier, const int8  *pbDataOne, int32 length)
    {
    	int8  leading[3];
    	int32 ileading;
    	int8 * tempStr = NULL;
    	int8 * ret;
    	int32 i = 0;
    
    	itoa(modifier/2, leading, 10);
    	ileading = atoi(leading);
    	tempStr = (int8 *) malloc(8);
    	ret = (int8 *) malloc(length);
    	memset(tempStr, 0, 8);
    	tempStr[0] = 0;
    
    	if( (modifier+1)%2 == 0 ) {
    		tempStr[0] = (int8)((ileading<<4) + 8);
    	}
    	else {
    		tempStr[0] = (int8)(ileading<<4);
    	}
    
    	for(i=0; i<(length>>3); i++)
    	{
    		xorStringRounds(ret+i*8, tempStr, pbDataOne+i*8, 8);
    	}
    	free(tempStr);
    	return ret;
    }
    
    int main(int argc, char **argv) {
    	int8 data[32];
    
    	memset(data, 0x0A, sizeof(data));
    	int8 *resp = oldModString(0xFF, data, sizeof(data));
    
    	free(resp);
    
    	return 0;
    }
    I put the reminder of the code underneath just in case if it needs to be clear to understand. I will keep looking for another solution.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    10
    By the way thanks I know I have been annoying everyone with this constantly but I just want to assure you all the I am not trying to get people to code I am just trying to find a small pieces of puzzle to put together. FYI the runtime error on this was a buffer overload (too many characters) Thanks

  3. #3
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    overloaded function differs only by return type from 'char *itoa(int,char *,int)'
    Sorry, but functions/methods can only be overloaded by arguments . . .

    At least, IIRC . . .
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  4. #4
    Sweet
    Join Date
    Aug 2002
    Location
    Tucson, Arizona
    Posts
    1,807
    Probably cause your compiler already has an itoa function defined.

    Try changing the name of your function or put it in a custom namespace
    Woop?

  5. #5
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Additionally, there are reasons why you should not use sprintf(). Same reasons as why not to use gets() -- buffer overflows. snprintf() is a better alternative.

    Not that it matters if you're not printing strings, however.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  6. #6
    Registered User
    Join Date
    Apr 2008
    Posts
    10
    Thanks again

  7. #7
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    So it all works? Everything's good?
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  8. #8
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,305
    Quote Originally Posted by Learner87 View Post
    I am playing with this code to see if I can get to work so far so good but I was curious what does this error message mean:

    overloaded function differs only by return type from 'char *itoa(int,char *,int)'
    It means that you're including a header file that already defines a function called itoa and it has the same parameters as yours, but it returns something different. This is a problem because when you call it, it doesn't know whether you're trying to call your one or that other one.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  9. #9
    Registered User
    Join Date
    Apr 2009
    Posts
    4
    Hello,

    Yes, after I changed the name of itoa function to my_itoa, the code runs fine. Its because of the itoa() also defined in stdlib.h
    However I have a question here?
    What exactly does oldModString() do? Is it just masking the values?

    --
    korn

  10. #10
    Registered User
    Join Date
    Jul 2009
    Posts
    1
    LOL. This portion of "code" is an exercise for a software developer position at a local company. This code is intentionally bloated and errors introduced to examine how a potentional coder would make the changes (style and functionality).

    Learner87 is an idiot and a fraud. He's posted this code multiple times and asked vague and mis-leading comments in regard to why. The fact that he's having problems with some of the very basic issues with this code means he's not ready for the position he's applying for. Please ignore these threads and/or remove them.

  11. #11
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Quote Originally Posted by FordmanIV View Post
    Learner87 is an idiot and a fraud.
    Maybe so, but you're the one that replies to 3 month old posts.
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. float calculation issue
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 05-26-2008, 04:56 AM
  2. overload *
    By shuo in forum C++ Programming
    Replies: 5
    Last Post: 06-10-2007, 04:44 AM
  3. Having trouble with operator*=()
    By Lurker in forum C++ Programming
    Replies: 10
    Last Post: 10-26-2003, 02:03 PM
  4. Buffer Overload
    By xddxogm3 in forum C++ Programming
    Replies: 1
    Last Post: 09-25-2003, 03:21 PM
  5. my first issue of GDM
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-12-2002, 04:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21