Programming Forums
User Name Password Register
 

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

Reply
 
Thread Tools Display Modes
Old Apr 6th, 2005, 7:53 AM   #1
Delete
Newbie
 
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0 Delete is on a distinguished road
C++ Classes - Quick question(s)

At the moment i'm learning classes in C++, i think i pretty much have the basic principles and syntax down but i have a few things i need clarified.

1. I've looked at some examples where the definitions are made inline in the .hpp class decloration. Is it wise to do this or should you always keep them seperate or does it depend on the program/class size?

2. Classes are equivilant to Structures? I've been looking at some socket programmming and they seem to make use of structs quite alot, although most of the socket programming i have seen is in C. So if these programs were to be re-written in C++ would they make use of classes instead of structures?

Please remember i'm still relatively new to this so be gentle.
Delete is offline   Reply With Quote
Old Apr 6th, 2005, 8:39 AM   #2
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
Keeping them separate is, AFAIK, a m atter of personal taste. Structs in C are like classes, but don't have methods/member functions. structs in C++ are the same as classes, but everything is by default public, not private.
uman is offline   Reply With Quote
Old Apr 6th, 2005, 8:57 AM   #3
Delete
Newbie
 
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0 Delete is on a distinguished road
ok - understood thx for the quick response.
Delete is offline   Reply With Quote
Old Apr 6th, 2005, 9:32 AM   #4
uman
Expert Programmer
 
Join Date: Dec 2004
Posts: 794
Rep Power: 4 uman is on a distinguished road
no problem, glad I could help.
uman is offline   Reply With Quote
Old Apr 6th, 2005, 2:27 PM   #5
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I, personally, use structs when I don't want functions, and classes when I do. Just a matter of taste, really.
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 6th, 2005, 3:00 PM   #6
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,467
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I've read somewhere... that structs basically are classes.

Personally, I use structs for "objects" that consist of multiple data types... and classes are a collection of structs and other data types and methods that perform actions on those types.
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 6th, 2005, 8:21 PM   #7
Cerulean
Professional Programmer
 
Cerulean's Avatar
 
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4 Cerulean is on a distinguished road
Quote:
So if these programs were to be re-written in C++ would they make use of classes instead of structures?
Precisely. The C-Socket API functions (connect, bind, send, recv), for example, would be made into a socket class (which is what i've made somewhere). Much more compact, much more tidy.
Cerulean is offline   Reply With Quote
Old Apr 7th, 2005, 12:08 PM   #8
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
I made me one of those... no idea how to use it...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old Apr 7th, 2005, 7:38 PM   #9
Delete
Newbie
 
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0 Delete is on a distinguished road
Thanx for all the fast replys very enlightening, cheers again.
Delete 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 7:43 PM.

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