Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

C++ Pointers


  • Please log in to reply
7 replies to this topic

#1 sausage

sausage

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:10:07 AM

Posted 09 February 2011 - 12:01 PM

monsters[i].Create('g',test.Occupied[24][80],rand() % 80, rand() % 24, rand() % 8 + 1,test.map[24][80]); //creates 40 Monsters

void Monster::Create(char sym, bool* OccupiedA[24][80],int x, int y,int hp, char* mapA[24][80]) //The constructor for Monster

37 G:\ApocalypseRL\main.cpp no matching function for call to `Monster::Create(char, bool&, int, int, int, char&)'
note G:\ApocalypseRL\global.h:35 candidates are: void Monster::Create(char, bool* (*)[80], int, int, int, char* (*)[80])

Explanation: The class Global is declared as test, and contains the map data; where objects are, and whether squares are occupied.

When Monster is created it is assigned a symbol ('g'), a pointer of the occupied spaces on the map, a random position (x, y), a random amount of health, and the specific map to use.

Occupied is a boolean, and map is a char.

What do I need to do here to make this work?

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:07 AM

Posted 09 February 2011 - 12:19 PM

When you are calling your function, the second function you are passing it is a boolean parameter contained at some position within an array. In your function, your second parameter is trying to get a boolean of type array, which makes no sense at all. A boolean is either true or false, and that is what you are passing to the function. Try making the second parameter something like 'bool b' or something.

You did the same thing with the last parameter also. You are passing the function a character, not an array, so something like 'char c' should work.

#3 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:10:07 AM

Posted 09 February 2011 - 03:47 PM

yes, they have to be arrays as each tile on the map uses a specific character, and each tile on the map is either occupied or not.

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:10:07 AM

Posted 09 February 2011 - 05:04 PM

Suppose I have an array that contains simply true(at 0) and false(at 1). If I want to pass that value to my a function, I can simply do this:
foo(myArray[0]);

My function doesn't care where that value came from; all I need to do is:
function foo(bool B);

The value at myArray[0] is a boolean value, and that is all I need to pass to my function. I do not need to pass the array unless I am trying to populate the array. In which case just pass the array. What I am trying to tell you is that your function call and your function declarations are mismatched.

#5 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:10:07 AM

Posted 09 February 2011 - 05:42 PM

The monster needs to be able to read and change every tile on the map. the reason that it's not specficially in the monster class is because the player class needs to read it as well, so I pass it to both the monster and the player, so they are both reading and changing the same map.

Edited by sausage, 09 February 2011 - 05:44 PM.


#6 Didier Stevens

Didier Stevens

  • BC Advisor
  • 2,698 posts
  • ONLINE
  •  
  • Gender:Male
  • Local time:06:07 PM

Posted 10 February 2011 - 10:09 AM

Occupied is a boolean, and map is a char.


No, like you wrote your code, Occupied is a two-dimensional array of pointers to a boolean, it is not a boolean.
*Occupied[0][0] is an example of a boolean.
Same goes for array map.

Like groovicus wrote, you should adapt the signature of method Create: the second argument should be type boolean.

Edited by Didier Stevens, 10 February 2011 - 10:10 AM.

Didier Stevens
http://blog.DidierStevens.com
http://DidierStevensLabs.com

SANS ISC Senior Handler
Microsoft MVP 2011-2016 Consumer Security, Windows Insider MVP 2016-2019
MVP_Horizontal_BlueOnly.png

 

If you send me messages, per Bleeping Computer's Forum policy, I will not engage in a conversation, but try to answer your question in the relevant forum post. If you don't want this, don't send me messages.

 

Stevens' law: "As an online security discussion grows longer, the probability of a reference to BadUSB approaches 1.0"


#7 sausage

sausage
  • Topic Starter

  • Members
  • 389 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Colorado
  • Local time:10:07 AM

Posted 10 February 2011 - 02:46 PM

Ok, yes, sorry I didn't explain it right, it wants to be a 2 dimensional array as the map is a two dimensional map, and each square of the map is either occupied or not.

#8 Romeo29

Romeo29

    Learning To Bleep


  • Members
  • 3,194 posts
  • OFFLINE
  •  
  • Gender:Not Telling
  • Location:127.0.0.1
  • Local time:11:07 AM

Posted 10 February 2011 - 09:02 PM

So you want to pass the whole array to your constructor ?
I think you should store the dimensions of the array somewhere as private members of the class.
And then pass arrays like this
bool Occupied[][28]
.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users