Click here to Skip to main content
15,905,068 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralBasic OOP question... Pin
Braulio Diez22-Nov-99 20:32
sussBraulio Diez22-Nov-99 20:32 
GeneralRE: Basic OOP question... Pin
Paul Selormey22-Nov-99 20:55
Paul Selormey22-Nov-99 20:55 
GeneralThanks but... Pin
Braulio Diez22-Nov-99 21:20
sussBraulio Diez22-Nov-99 21:20 
GeneralRE: Thanks but... Pin
Henk Devos23-Nov-99 9:27
Henk Devos23-Nov-99 9:27 
GeneralRE: Basic OOP question... Pin
sandrine22-Nov-99 22:07
sandrine22-Nov-99 22:07 
GeneralRE: RE: Basic OOP question... Pin
Braulio Diez23-Nov-99 1:57
sussBraulio Diez23-Nov-99 1:57 
GeneralRE: RE: RE: Basic OOP question... Pin
Anonymous23-Nov-99 7:41
suss Anonymous23-Nov-99 7:41 
GeneralRe: Basic OOP question... Pin
Member 147421-Apr-00 11:01
Member 147421-Apr-00 11:01 
This is a basic C++ question, not OOP.

When ever you create a class the compiler automatically creates a default constructor and a copy constructor. The default constructor is required if you want to create objects like this:

CFoo foo;


As soon as you create ANY constructor, the compiler requires you to write ALL constructors. In other words, it no longer creates the default constructor for you. That means if you write:

struct Point
{
  int x;
  int y;
};

Point origin; // legal - using compiler-supplied default constructor


...but if you write this...

struct Point
{
  int x;
  int y;
  Point(int x, int y): x(x), y(y) {}
};


...the compiler no longer generates the default constructor...

Point origin; // illegal! no default constructor
Point origin (12,45); // legal - using Point(int,int)


Note that a default constructor does not have to take 0 arguments, you simply must be able to call it with 0 arguments. Like this...

struct Point
{
  int x;
  int y;
  Point(int x=0, int y=0): x(x), y(y) {} // default parameters
};


Now everything's happy again...

Point origin; // legal - using Point(int,int)
Point origin (12,45); // legal - using Point(int,int)


Hope this clarifies more than it confuses!

Cheers,
Eric
GeneralDebugging Control Panel Applets Pin
Farzad Bakhtiar9-Apr-00 21:56
sussFarzad Bakhtiar9-Apr-00 21:56 
GeneralGetFieldValue() throws an exception Pin
Stefan20-Nov-99 5:25
Stefan20-Nov-99 5:25 
GeneralRE: GetFieldValue() throws an exception Pin
Member 40424-Nov-99 9:38
Member 40424-Nov-99 9:38 
GeneralRe: a step by step running Pin
goldmount19-Nov-04 3:25
goldmount19-Nov-04 3:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.