Thread: Semicolon at end of class?

  1. #1

    Question Semicolon at end of class?

    Why after you declare a class do you have to put a semicolon after the ending bracket?

  2. #2
    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..."

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    119
    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

  4. #4
    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.

  5. #5
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    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 .

  6. #6
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    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 .
    That's just because of a typedef, you can do that with any datatype.

    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.)

  7. #7
    Registered User
    Join Date
    Nov 2002
    Posts
    18
    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

  8. #8
    Registered User
    Join Date
    Sep 2001
    Posts
    305
    yeah i looked it up. theres like 5 ways to do it. anyways, excuse my ignorance .

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 09:35 AM
  3. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM