Why after you declare a class do you have to put a semicolon after the ending bracket?
Why after you declare a class do you have to put a semicolon after the ending bracket?
B/C you can name an instance after the declartation...
class A{
}InstanceOfA;
EDIT: I forget if it's an instance or an Alias
My Avatar says: "Stay in School"
Rocco is the Boy!
"SHUT YOUR LIPS..."
Originally posted by OneStiffRod
EDIT: I forget if it's an instance or an Alias
It's an instance of the class.
But I don't know about that being the reason for the semi-colon
-Futura
If you speak or are learning Spanish, check out this Spanish and English Dictionary, it is a handy online resource.
What happens is not as important as how you react to what happens. -Thaddeus Golas
Because you aren't implementing the class you are declaring it. Even though you are doing the
class CMyClass
{
int a, b;
};
method, you are really just declaring a type, kinda like a typedef. Oh, and you can make an instance of it as well, and the semicolon tells when you are done making instances.
in C, when you define a struct, you can name it at the end of the declaration. forgot exactly how, but im pretty sure the reason for the semicolon is the struct .
That's just because of a typedef, you can do that with any datatype.Originally posted by Flikm
in C, when you define a struct, you can name it at the end of the declaration. forgot exactly how, but im pretty sure the reason for the semicolon is the struct .
IE
typedef int Thing; // Makes Thing an alias for int
typedef struct { int a; } OtherThing; // Makes OtherThing an alias for that particular type of struct.
The reason for the semicolon, as people said, is just to show that you aren't creating any instances (or to show the end of the list of instances and/or pointers to instances, or arrays of instances, etc.)
Flik, the syntax is this:
Code:#ifndef _MAIN_H_ #define _MAIN_H_ #include <stdio.h> #include <stdlib.h> typedef struct _STRUCT { int x; int y; }STRUCT; // Now if you wanted to make an instance you would use STRUCT as the data type not _STRUCT. #endif
yeah i looked it up. theres like 5 ways to do it. anyways, excuse my ignorance .