C++ people,......

AFB

Lifer
Jan 10, 2004
10,718
3
0
WTF is with seperate function and class declaration and definition ? That's just weird.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Works for me ... I kind of like having the decaration & implementation seperate. Especially when things get big.
 

AFB

Lifer
Jan 10, 2004
10,718
3
0
I can see that, I just can't see why you don't define the methods within the class.

Like:
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
ic ... your referring to inline functions. Sometimes if I can do it all on one line, I'll do it right in the class definition:

float getAge(void) {return age;}

But ussually, I find it more readable to just put decalrations & comments on usage in the class definition. Then, most of the time, I just have to look at the class definition (reasonable short & clean) to find the functions I need and how to use them, instead of having it cluttered up with code.
 

EmperorRob

Senior member
Mar 12, 2001
968
0
0
Yeah when you have a class with 14 complex functions it's much easier to see immediately what functions are available to a class. Plus it gives you a chance to put all the declarations in a header file so your users (if you have any) can just look at the prototype of your mehtod.
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Same reason for C function declarations/definitions. C++ is derived from C, remember? You can put the method bodies right into the class declaration, but that will make them inline.
 

Sureshot324

Diamond Member
Feb 4, 2003
3,370
0
71
Originally posted by: EmperorRob
Yeah when you have a class with 14 complex functions it's much easier to see immediately what functions are available to a class. Plus it gives you a chance to put all the declarations in a header file so your users (if you have any) can just look at the prototype of your mehtod.

Yeah, if anyone else wants to use your code for some other project, they just want to know what functions and classes are available, and what they do. They don't care how they actually work, so it's much easier to just look at a header file with the declarations.
 
Feb 28, 2004
72
0
0
Originally posted by: BingBongWongFooey
Same reason for C function declarations/definitions. C++ is derived from C, remember? You can put the method bodies right into the class declaration, but that will make them inline.

Is that also true when you define C++ templates?
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
because in c++ you need to include the class definition in source code form, and seperate declaration and definition allow you to seperate the class defintions and method defitions into seperate files, this allows for faster compilation (since the compiler has to compile the method definition file only once where as the class definition header can be included hundreds of times) and hiding of code (if you supply the method defnitions only in compiled form)
 

dighn

Lifer
Aug 12, 2001
22,820
4
81
Originally posted by: BingBongWongFooey
You can put the method bodies right into the class declaration, but that will make them inline.

are you sure about that?
 

Barnaby W. Füi

Elite Member
Aug 14, 2001
12,343
0
0
Originally posted by: MajorCatastrophe
Originally posted by: BingBongWongFooey
Same reason for C function declarations/definitions. C++ is derived from C, remember? You can put the method bodies right into the class declaration, but that will make them inline.

Is that also true when you define C++ templates?

I don't think that being a template class makes any difference, but I'm not totally sure.