• Advertisement
Sign in to follow this  

Does this work?

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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;

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 declaration
Example *pStruct; // can one write like this without struct?
struct Example *pStruct; // or must one write like this?


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
But in C I must write struct before a struct variable if I write the struct a this:

struct Example {
int someInt;
char *someString;
};

// variable declaration
Example *pStruct; // Works in C++, but not in C?
struct Example *pStruct; // In C I have to, in C++ I don't have to?



The question was if I must write struct before in struct variable declarations?
Confirm:
In C I must?
In C++ it works without?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Can one construct a new instance in the same variable after destructing a class?

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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Rather than resurrecting an old post, you would be better off creating a new topic and putting it in the correct (OpenGL) forum.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement