| pholotic (29) | |||
|
I would like to know the proper way of declaring variables that are relative to a class (file) using ADTs. I'm working on a small project which involves a good amount of variables, most of which relate directly to one of my header & implementation files. Here is an example:
When working with ADTs, should I be declaring all of those variables within the private of the class, or should those variables be declared throughout, or initially, in the implementation file?? Also, might anyone know of a good read for the do's and dont's when working with ADTs AND classes? All help is greatly appreciated. Thank you. | |||
|
|
|||
| pholotic (29) | |
| No ideas? | |
|
|
|
| vlad from moscow (3656) | |
| It is not clear what you are saying about. What variables are you speaking about? I see only a class definition and its data members. You already declared them as private. It is a good idea to hide the realization inside the class and provide an open interface as public methods. | |
|
|
|
| pholotic (29) | |||
|
Thank you vlad. I think you may have stated my query a little better. Although, I'm not exactly concerned with if the variables (members) should be public or private. It's more an issue of whether or not they should be declared within the class at all, or declared within the .cpp implementation file. Implementation file:
Technically I guess both could work? But I think there would have to be a lot of data copying to do if all or most variables were declared at random. I'm getting concerned with the project I am working on because I'm starting to notice that I'm declaring quite a lot of private members. Also, I've noticed that none of the many member functions I have pass any parameters. There issues are having me wonder if I'm doing things correctly. I appreciate the help. | |||
|
|
|||
| JLBorges (1754) | |
|
> a good read for the do's and dont's when working with ADTs AND classes? 'Ruminations on C++' by Koenig has a chapter called 'Checklist for Class Authors.' The list of issues covered are reproduced here: http://lkmsoftware.wordpress.com/2007/01/11/checklist-for-c-class-authors/ > It's more an issue of whether or not they should be declared within the class at all Yes. Variables that together define the state of an object of that type. | |
|
|
|