object multi reference



 DEVELOP > c-Plus-Plus > object multi reference

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Gary Wessle"
Date: 29 Aug 2006 12:08:20 PM
Object: object multi reference
Hi
I have a program consisting of few .cpp and .h files with few
classes. the objects need to read and write to the disk and check on
what other objects are doing. to centralize the disk-location info, I
created a g_inf class which serves as placeholder of paths for
directories and files info.
class g_inf{
string building_dir;
string tenants_dir;
string tena_file_ext;
...
public:
g_inf();
};
g_inf::g_inf()
: building_dir("/path/"),
...
{}

in the main, I do
int main(){
g_inf dsk_inf();
myType group(&dsk_inf, ...
anotherType them(&des_inf, ...
thirdType(&dsk_inf, &myType, ...
is this a safe way to do it?
thanks
.

User: "Alan Johnson"

Title: Re: object multi reference 29 Aug 2006 01:20:21 PM
Gary Wessle wrote:

Hi

I have a program consisting of few .cpp and .h files with few
classes. the objects need to read and write to the disk and check on
what other objects are doing. to centralize the disk-location info, I
created a g_inf class which serves as placeholder of paths for
directories and files info.

class g_inf{
string building_dir;
string tenants_dir;
string tena_file_ext;
...
public:
g_inf();
};
g_inf::g_inf()
: building_dir("/path/"),
...
{}

in the main, I do

int main(){
g_inf dsk_inf();

This declares a function named dsk_inf that takes 0 parameters and
returns a g_inf. Very likely not what you intended to do. Try:
g_inf dsk_inf;

myType group(&dsk_inf, ...
anotherType them(&des_inf, ...
thirdType(&dsk_inf, &myType, ...

is this a safe way to do it?

thanks

This seems like a safe way, yes, though if it is just a bunch of global
data you may want to consider just using a namespace. i.e:
// g_inf.h
namespace g_inf
{
extern const string building_dir ;
// other data
}
// g_inf.cpp
namespace g_inf
{
const string building_dir("/path/") ;
// other data
}
If it is more than just data then the Singleton or Monostate patterns
may apply (though in my opinion these patterns should be used sparingly
and only after several other designs have been considered).
--
Alan Johnson
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER