Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 23rd, 2007, 4:32 PM   #1
JJH35
Newbie
 
Join Date: Nov 2006
Posts: 6
Rep Power: 0 JJH35 is on a distinguished road
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?
JJH35 is offline   Reply With Quote
Old Apr 23rd, 2007, 5:12 PM   #2
Klarre
Game engine designer
 
Klarre's Avatar
 
Join Date: May 2005
Location: Sweden
Posts: 310
Rep Power: 4 Klarre is on a distinguished road
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
Klarre is online now   Reply With Quote
Old Apr 23rd, 2007, 6:19 PM   #3
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 225
Rep Power: 3 Seif is on a distinguished road
a good detailed explaination on inline functions here, including the advantages / disadvantages on inline functions :

http://www.parashift.com/c++-faq-lit...functions.html
Seif is offline   Reply With Quote
Old Apr 23rd, 2007, 11:06 PM   #4
JJH35
Newbie
 
Join Date: Nov 2006
Posts: 6
Rep Power: 0 JJH35 is on a distinguished road
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
}

??
JJH35 is offline   Reply With Quote
Old Apr 23rd, 2007, 11:13 PM   #5
JJH35
Newbie
 
Join Date: Nov 2006
Posts: 6
Rep Power: 0 JJH35 is on a distinguished road
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!
JJH35 is offline   Reply With Quote
Old Apr 24th, 2007, 12:46 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Apr 25th, 2007, 10:44 AM   #7
Soulstorm
Hobbyist Programmer
 
Soulstorm's Avatar
 
Join Date: Jan 2006
Location: Menidi, Athens, Greece
Posts: 243
Rep Power: 3 Soulstorm is on a distinguished road
yup, some code tags would make members more helpful.
__________________
Project::Soulstorm (personal homepage)
Soulstorm is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:55 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC