Putting the 'role' back in role-playing games since 2002.
Donate to Codex
Good Old Games
  • Welcome to rpgcodex.net, a site dedicated to discussing computer based role-playing games in a free and open fashion. We're less strict than other forums, but please refer to the rules.

    "This message is awaiting moderator approval": All new users must pass through our moderation queue before they will be able to post normally. Until your account has "passed" your posts will only be visible to yourself (and moderators) until they are approved. Give us a week to get around to approving / deleting / ignoring your mundane opinion on crap before hassling us about it. Once you have passed the moderation period (think of it as a test), you will be able to post normally, just like all the other retards.

I need a workaround for C++ limitations on fixed array size.

desocupado

Magister
Joined
Nov 17, 2008
Messages
1,802
So, you guys know this:
double happy_array[multiple*happiness];
is not allowed in C++. Only:
double fuck_you_array[const_value_of_dicks];
is.

Thing is, I have a class that takes a double* as argument, but I really need the number of elements to be defined at run-time.

Any ideas?
 

desocupado

Magister
Joined
Nov 17, 2008
Messages
1,802
Derp. I think using new[] should do the trick.
Maybe.

EDIT: NEVERMIND, new[] did the trick. Sorry to bother, but for some reason I can't delete the thread.

Dumb questions, that's what you get for programming when your brainpower is already spent.
 
Last edited:

Declinator

Arbiter
Joined
Apr 1, 2013
Messages
542
Alternatively, if C++11 features are available, you could use a std::unique_ptr<double> array and not need to worry about deletion.

Still, a vector is probably the better option in almost all cases. You can reserve the needed space immediately so as to avoid multiple allocations with reserve().
 

Norfleet

Moderator
Joined
Jun 3, 2005
Messages
12,250
Yes, remember to delete it when you're done, though. If you new things and don't delete them, they hang around in memory forever, lost in space, and your program leaks memory until it runs out and goes boom. Don't do that. C++ is an oldschool language, not that newfangled popamole managed stuff.
 

Twiglard

Poland Stronk
Patron
Staff Member
Joined
Aug 6, 2014
Messages
7,237
Location
Poland
Strap Yourselves In Codex Year of the Donut
Actually with C++11 it's idiomatic to have the memory automatically managed, std::make_shared and friends. Modern C++ doesn't look like "C with classes" anymore.
 

As an Amazon Associate, rpgcodex.net earns from qualifying purchases.
Back
Top Bottom