![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0
![]() |
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. ![]() |
|
|
|
|
|
#2 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
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.
|
|
|
|
|
|
#3 |
|
Newbie
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0
![]() |
ok - understood thx for the quick response.
|
|
|
|
|
|
#4 |
|
Expert Programmer
Join Date: Dec 2004
Posts: 794
Rep Power: 4
![]() |
no problem, glad I could help.
|
|
|
|
|
|
#5 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I, personally, use structs when I don't want functions, and classes when I do. Just a matter of taste, really.
|
|
|
|
|
|
#6 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#7 | |
|
Professional Programmer
Join Date: Apr 2005
Location: London, England
Posts: 459
Rep Power: 4
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
I made me one of those... no idea how to use it...
|
|
|
|
|
|
#9 |
|
Newbie
Join Date: Apr 2005
Location: Ireland
Posts: 12
Rep Power: 0
![]() |
Thanx for all the fast replys very enlightening, cheers again.
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|