![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2006
Posts: 6
Rep Power: 0
![]() |
constructor help...
i was working on an assignment and we usually declare the constructor in this example
class test { public: test(); then the rest of the stuff obviously i noticed a program doing it this way and wasn't sure what its doing class test { public: test() {} no semicolon and the open/close braces... what is the diff or why is it used? |
|
|
|
|
|
#2 |
|
Game engine designer
Join Date: May 2005
Location: Sweden
Posts: 310
Rep Power: 4
![]() |
The difference is that in the first example, the constructor is just declared. You also have to define it in your cpp file. In the other example, with the braces, the definition is done, what is called, "inline". Search on google for inlineing code in C++ and you will get some good explanations.
__________________
http://www.klarre.se |
|
|
|
|
|
#3 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: UK
Posts: 225
Rep Power: 3
![]() |
a good detailed explaination on inline functions here, including the advantages / disadvantages on inline functions :
http://www.parashift.com/c++-faq-lit...functions.html |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Nov 2006
Posts: 6
Rep Power: 0
![]() |
how would i change this which is inline then to the regular declaration of doctor();
class doctor { public: doctor(){} doctor(const char *n) { strcpy(name,n); for(int col=0;col<41;col++) appointments[col]=NULL; } }; just move the doctor(const char *n) stuff outside the close class and declare it as doctor::doctor(const char *n){ stuff inside } ?? |
|
|
|
|
|
#5 |
|
Newbie
Join Date: Nov 2006
Posts: 6
Rep Power: 0
![]() |
nevermind i believe i figured it out, thanks for the information, made it clear what the program was trying to do, so i was able to change it to how i wanted it
appreciate the help! |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
JJH35, please read the forum's faq/rules before posting more code.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 |
|
Hobbyist Programmer
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3
![]() |
yup, some code tags would make members more helpful.
__________________
Project::Soulstorm (personal homepage) |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|