Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 147 148 [149] 150 151 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 841235 times)

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2220 on: April 19, 2012, 08:42:31 am »

I'm trying to alter attributes of the objects themselves.
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2221 on: April 19, 2012, 08:44:50 am »

In that case you could use Object** objects in the parameters (or something along those lines), and use objects to access an object. Keep in mind that objects is going to be a pointer.
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2222 on: April 19, 2012, 09:03:18 am »

I don't follow what you mean there. Do you mean just to change the parameters to (Object** objects[]) or something more complicated?
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2223 on: April 19, 2012, 09:06:04 am »

Well, you could go with Object* objects[], but a C++ compiler doesn't distinguish between that and Object** objects.
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2224 on: April 19, 2012, 09:09:13 am »

Oh. That's like the first thing I tried. Still no dice. Tells me there's no matching function for the call.
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2225 on: April 19, 2012, 09:13:51 am »

Alright then. Firstly: what is the function signature in question? Secondly: can you show me the definition of the array in your code?
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2226 on: April 19, 2012, 09:17:18 am »

Code: [Select]
bullet* Bullets[MAX_BULLETS];MAX_BULLETS being a constant int.

Assuming the function signature is the declaration/prototype:
Code: [Select]
void Shoot(bullet* Bullets[]);
Logged

RulerOfNothing

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2227 on: April 19, 2012, 09:21:21 am »

Well, I think there is no reason why that shouldn't work, but I have never had a clear picture of the minutae of C++'s type system (I usually try to keep away from such dark corners). I'm not too sure if I can provide any assisstance unfortunately.
Logged

Simmura McCrea

  • Bay Watcher
    • View Profile
    • My Steam profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2228 on: April 19, 2012, 09:24:19 am »

The exact error it gives is
Quote
no matching function for call to 'player::Shoot(bullet*&)'
candidates are: void player::Shoot(bullet**)
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2229 on: April 19, 2012, 09:33:54 am »

And you're simply calling it as shoot(Bullets), not shoot(&Bullets) or something?
Hmmz.

This is one of the reasons I never use arrays :)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2230 on: April 19, 2012, 09:41:47 am »

I don't believe you can pass normal arrays through function calls like that.


Remember, arrays are just pointers. They are nothing more than that. They point to a block in memory and using the array brackets just offsets the address. If you want to pass an array, I'd suggest passing a vector or somesuch instead.


EDIT: In fact I'd suggest stop using arrays entirely and switch to vectors or something in the boost library. Their pointer nature adds a hell of a lot of overhead in specific situations that you do not want to deal with.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2231 on: April 19, 2012, 10:25:41 am »

Stargrasper = null;

I wish it were that simple in practice.  You know very well how things like to screw up if you so much as look at it funny.  At least when it segfaults, valgrind will give decent errors, unlike g++.

I don't believe you can pass normal arrays through function calls like that.


Remember, arrays are just pointers. They are nothing more than that. They point to a block in memory and using the array brackets just offsets the address. If you want to pass an array, I'd suggest passing a vector or somesuch instead.


EDIT: In fact I'd suggest stop using arrays entirely and switch to vectors or something in the boost library. Their pointer nature adds a hell of a lot of overhead in specific situations that you do not want to deal with.

I disagree with you, arrays are a lot more efficient if you happen to know how much stuff is going to be in them.  There's nothing stopping you from passing arrays as parameters to functions.  It's mildly annoying, but easily done if that's what you want to accomplish.
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2232 on: April 19, 2012, 10:30:07 am »

I actually do use arrays with large blocks of data like bitmaps and graphics textures, but for normal use I avoid them like the plague.


One problem I nearly spent a week on was using arrays for object variables. I had these objects in a vector, and whenever it resized, the arrays lost protection and were randomly overwritten. Segfaults that happen at indeterminate times suck.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2233 on: April 19, 2012, 11:15:45 am »

Yeah, never use a vector if the address of the stored data matters. You'd have to use a list for that. Or write your own "arraylist" structure that creates blocks of members at a time. It's not that tricky, but the performance suffers compared to a vector since Random access still requires traversing a list.

It's not like you need to worry about shrinking on a pop, in most implementations and most situations a standard type will not shrink. Not in Java, not in C# and not in C++. Some consider it a bug, others a feature.

And if you need a fixed size array, ladies, gentleman: std::array.
« Last Edit: April 19, 2012, 11:17:35 am by MorleyDev »
Logged

Sowelu

  • Bay Watcher
  • I am offishially a penguin.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2234 on: April 19, 2012, 02:22:38 pm »

The exact error it gives is
Quote
no matching function for call to 'player::Shoot(bullet*&)'
candidates are: void player::Shoot(bullet**)

I may be able to help.  How are you calling it?
Logged
Some things were made for one thing, for me / that one thing is the sea~
His servers are going to be powered by goat blood and moonlight.
Oh, a biomass/24 hour solar facility. How green!
Pages: 1 ... 147 148 [149] 150 151 ... 796