Quick function Q

This is a discussion on Quick function Q within the C++ Programming forums, part of the General Programming Boards category; I have these two funtions in my .h file. They both have the same name but arnt the same as ...

  1. #1
    Registered User
    Join Date
    Mar 2007
    Posts
    37

    Quick function Q

    I have these two funtions in my .h file. They both have the same name but arnt the same as shown below :-

    Code:
     
    
    Square * getSquare(int x, int y);
    Square * getSquare(int index);
    If i was to call one in my .cpp, could it get confused with tthe two if i don't specify which one??

    for example:-

    Code:
    Square * s = board->getSquare(d1s->getX()+1, d1s->getY() +1); 			
    Square * o = board->getSquare(d1s->getX()+2, d1s->getY() +2);
    i am assuming not, becuase the two arguments i give match the first function??

  2. #2
    Obsessed with C chrismiceli's Avatar
    Join Date
    Jan 2003
    Posts
    501
    Due to C++'s ability to overload functions, if
    d1s->getX()+1 and
    d1s->getY() +1
    are types convertable to ints, the compiler should know to call the two parameter function with type ints.
    Help populate a c/c++ help irc channel
    server: irc://irc.efnet.net
    channel: #c

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    7,344
    >> If i was to call one in my .cpp, could it get confused with tthe two if i don't specify which one?
    One of those takes one parameter, the other takes two. The compiler will know which one to use based on whether you pass in one argument or two. Both your examples pass two arguments, so both will use the first function.

  4. #4
    Registered User
    Join Date
    Mar 2007
    Posts
    37
    cool, thanks, i thought that might be causing the problem in the game, but now i found the problem, i had x and y the wrong way round in one of my .cpp's, gosh, u gota love coding......

  5. #5
    Registered User
    Join Date
    Mar 2007
    Posts
    92
    Man, I've had so many of those. I've spent countless hours trying to find retarded mistakes like that. Not that you're retarded in doing it, just retarded it takes so long for something that trivial.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  2. doubt in c parser coding
    By akshara.sinha in forum C Programming
    Replies: 4
    Last Post: 12-23-2007, 01:49 PM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 01:03 PM
  5. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM

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