Jump to content
  • Advertisement
Sign in to follow this  
programering

Does this work?

This topic is 4538 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!