473,378 Members | 1,355 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
Aug 29 '06 #1
1 1429
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

Aug 29 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's...
4
by: Frank Jona | last post by:
Intellisense with C# and a multi-file assembly is not working. With VB.NET it is working. Is there a fix availible? We're using VisualStudio 2003 Regards Frank
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
22
by: Dr Duck | last post by:
GDay all, Something seems odd to me.... I wrote a simple C# function public void bind(ref object a, ref object b, bool atob) { if(atob) b = a; else
2
by: george r smith | last post by:
I understand that when you compare (using ==) objects you are seeing if they both refer to the same object. My question why or when would you ever use multiple references to the same object. What...
5
by: Seeker | last post by:
Hello, I've read conflicting posts about . Does it or does it not lock the entire object? In my simple test it appears to block just the method but I wouldn't exactly call my meager test...
1
by: Robert A Riedel | last post by:
I am completely baffled when the following managed exception is thrown: "Object reference not set to an instance of an object" from a nested subroutine when referencing a variable allocated on the...
6
by: Clark Sann | last post by:
Can someone help me understand what object should be used as the lock object? I've seen some programs that use Monitor.Enter(Me). Then, in those same programs, they sometimes use another object. ...
17
by: Divick | last post by:
Hi, I am designing an API and the problem that I have is more of a design issue. In my API say I have a class A and B, as shown below class A{ public: void doSomethingWithB( B * b) { //do...
4
by: IanONet | last post by:
I had a need for a two dimentional array. Looking for this solution, I ran accross a statement than all Javascipt arrays were arrays of objects. So I created a function prototype, at least thats...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.