Thread: More pointer woes.

  1. #1
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100

    More pointer woes.

    Ok so i'm trying to build the member-function of the class that controls the movement of the enemies, and too implement some basic collision detection i want to pass it the address of the pointers of the player character and the enemies array that are on the heap.

    so i tried prototyping;

    Code:
     
     void move(Player * &thePlay, Enemy * &enemys);
    and calling it with;

    Code:
    enemys[1]->move(thePlay,enemys)
    but i get the error 444no matching function for call to `Enemy::move(Player*&, Enemy*[4])'

    i'm sure the answer is obvious, but i don't know it!
    Sorry, but i'm a Code::Blocks man now.

  2. #2
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Why do you really need the addresses of the pointers to do collision detection in the first place? You need the player data and access to the play area to do that. The location of the pointers which hold these things should be of no interest to you. Simplify!

  3. #3
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    This also makes no sense to me:
    enemys[1]->move(thePlay,enemys)
    You are calling the function on an object in the array and pass the same array as an argument.
    But the error also says that enemys (which is spelled enemies, btw) is not of the type the function expects. In other words, the prototype in this case is wrong. But you should follow citizen's suggestion, though, I think.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  4. #4
    Registered User Terran's Avatar
    Join Date
    May 2008
    Location
    Nashua, NH
    Posts
    100
    well the way i was doing it is to have the member function that moves them check to make sure that the move it comes up with is legal by checking where everything else in the level is then to just return true back to the main loop. that way the only thing the main loop is doing is calling the basic functions and passing pointers!

    edit: i know it's spelled wrong, i just didn't feel like typeing the extra letters over and over again.

    edit again: Ok i'll simplify. I should stop practicing to be a Microsoft programmer anyways.
    Last edited by Terran; 06-08-2008 at 10:12 AM.
    Sorry, but i'm a Code::Blocks man now.

  5. #5
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Terran View Post
    edit: i know it's spelled wrong, i just didn't feel like typeing the extra letters over and over again.
    Enemys
    Enemies
    Oh, come on, is one letter extra too much for you?
    It seems more like a spelling mistake than laziness
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    BTW, since enemys is an array you can't pass it as a reference. If your design was correct you'd just have to change it to Enemy** (or Enemy*[] or Enemy*[4]).

  7. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    You could also change it to "Enemy *(&enemies)[4]". It's better than Enemy*[4], since the 4 actually means something.
    Last edited by King Mir; 06-09-2008 at 02:11 AM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    That's even more confusing.
    Does the function really need to modify the enemy object? Otherwise a pointer might do.
    Or better yet, a vector. Passing a vector by reference is no biggie.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  2. Parameter passing with pointer to pointer
    By notsure in forum C++ Programming
    Replies: 15
    Last Post: 08-12-2006, 07:12 AM
  3. Direct3D problem
    By cboard_member in forum Game Programming
    Replies: 10
    Last Post: 04-09-2006, 03:36 AM
  4. How did you master pointers?
    By Afrinux in forum C Programming
    Replies: 15
    Last Post: 01-17-2006, 08:23 PM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM