Skip to main content
GameDev.net gamedev.net
🔒 Locked

Does this work?

Started by programering Apr 5, 2006 at 12:12 PM 12 replies 1.3k views
Original Post
programering
programering

typedef float Matrix[4][4];

typedef Uint8 Uint24[3];


class Example {
   int someVariable;
   Example(int someParameter)
   {
      someVariable = someParameter;
   }
}

. . .

Example *classArray;

. . .

classArray = new Example(32)[8];

Does that work? I don't know, therefore I use the vector, like this:

#include <vector>
std::vector<Example *> classVector;

haegarr
haegarr
typedef float Matrix[4][4];typedef Uint8 Uint24[3];

Yes. (Actually I was surprised after trying it; I haven't thought that it is working :)

class Example {   int someVariable;   Example(int someParameter)   {      someVariable = someParameter;   }}

Yes, but is useless since all is private.

classArray = new Example(32)[8];

No. AFAIK only default c'tors are possible with arrays.
NotAYakk
NotAYakk
If you fix the "all your members are private" problem, then:
std::vector<Example> v;v.resize(32, Example(32));

does something like what you want.

I would also advise for you to look into the boost array classes.

programering
programering
About private: it was just an example.

And about structs, if one don't typedef, Must one always write the keyword struct before in variable declarations?

How I write struct's with typedef:
typedef struct {   int someInt;   char *someString;} Example;Example *pStruct;  // variable declaration


Without typedef:
struct Example {   int someInt;   char *someString;};// variable declarationExample *pStruct; // can one write like this without struct?struct Example *pStruct; // or must one write like this?
programering
programering
Do you guys know if that works, or must I write struct in variable declarations?
Oluseyi
Oluseyi
No, once you use typedef, you no longer need struct - in C.

In C++, you don't even need typedef. struct is identical to class, but in a way that is backward compatible with C - ie, it defaults to public access and public inheritance.
Bregma
Bregma
Quote:
Original post by Anonymous Poster
The question was if I must write struct before in struct variable declarations?
Confirm:
In C I must?
In C++ it works without?


Yes.

Stephen M. Webb
Professional Free Software Developer
programering
programering
Can one destruct a derived's class it's base class?
programering
programering
Can one construct a new instance in the same variable after destructing a class?

SomeClass classVar(76,"87jh");
delete classVar;
classVar(564"whgft");
Bregma
Bregma
Quote:
Original post by programering
Can one construct a new instance in the same variable after destructing a class?

SomeClass classVar(76,"87jh");
delete classVar;
classVar(564"whgft");


This won't compile. The delete operator takes a pointer-to-object, not an object instance. You could do something like the following.
  SomeClass *pClassVar = new SomeClass(76, "87jh");  delete pClassVar;  pClassVar = new SomeClass(564"whgft");

Or you could assign new values like this.
  SomeClass classVar(76,"87jh");  classVar = SomeClass(564"whgft");

Either of these should have the effect you want (um, I think).
Stephen M. Webb
Professional Free Software Developer
programering
programering
Thank you Bregma!
rating += 10 had no effect.

Does this work?:
#define TEST_MACRO test  // macro#if TEST_MACRO == test// compile this#elif TEST_MACRO == macro// compile this#endif
programering
programering
This is an OpenGL question however:
Can one turn off the z/depth buffer feature?
With glDisable(GL_DEPTHBUFFER), or something?
I was just wondering cos I got an idea of the thing rendering craters on a surface.
Dave Hunt
Dave Hunt
Rather than resurrecting an old post, you would be better off creating a new topic and putting it in the correct (OpenGL) forum.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.