View Single Post
  #3 (permalink)  
Old 08-02-2007, 06:25 PM
Bench Bench is offline
Full Programmer
Join Date: Jul 2007
Location: UK
Posts: 113
iTrader: (0)
Bench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished roadBench is on a distinguished road
struct and class are both the same thing in C++. With one minor caveat. The default access specifier for members of a class is private. the default access specifier for members of a struct is public. Otherwise, they're identical.

struct was inherited from 'C', which had no notion of OOP or classes, so, as a tradition/convention, the struct keyword is only used when the struct only contains data (And maybe some extremely trivial constructors or methods). eg, a coordinate struct for holding 2D 'x' and 'y' values in a graph
Code:
struct coordinate
{
    int x;
    int y;
    coordinate(int xx, int yy)
    {
        x = xx;
        y = yy;
    }
}; //Don't forget the semicolon

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to Bench For This Useful Post:
HelloWorld (08-02-2007)