473,382 Members | 1,376 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,382 software developers and data experts.

global object(s) construction


When constructing - in this case static objects I've been advised to
use a 'manager' class. The desired order of construction per the
'sample/test' source below:

1. ic_msg
2. rec
3. rec_win_impl
4. main_win_impl

So now consider:

// msg_impl.h
#ifndef MSG_IMPL_H
#define MSG_IMPL_H

# include <iostream>
# include "rec.h"

extern class rec m_rec;

struct ic_msg {
void execute() {
//m_rec.update(*this);
}
ic_msg() {
std::cout << " ic_msg constructed " << std::endl;
}
};
#endif

// rec.h
#ifndef REC_H
#define REC_H

# include <iostream>
# include "msg_impl.h"

class rec {
friend struct ic_msg;
ic_msg m_msg;

void update(ic_msg& msg)
{
m_msg = msg;
}
public:
rec() {
std::cout << " rec constructed " << std::endl;
}
~rec() {}
void do_some_special_thing()
{
m_msg.execute(); // this is really called polymorphically but
// done/show for demonstration
}
};

#endif

//rec_win_impl.h
#ifndef REC_WIN_IMPL_H
#define REC_WIN_IMPL_H

# include <iostream>
# include "rec.h"

rec m_rec;
class rec_win_impl {
//rec *m_rec; // dynamic / 'old' approach
public:
rec_win_impl() {
// m_rec = new rec(); // dynamic / 'old' approach
std::cout << " rec_win_impl constructed " << std::endl;
}
~rec_win_impl() {}
};

#endif
// main_win_impl.h
#ifndef MAIN_WIN_IMPL_H
#define MAIN_WIN_IMPL_H

# include <iostream>
# include "rec_win_impl.h"

rec_win_impl m_rec_impl;

class main_win_impl {
// rec_win_impl *m_rec_impl; // dynamic / 'old' approach
public:
main_win_impl() {
// m_rec_impl = new rec_win_impl(); // dynamic / 'old' approach
std::cout << " main_win_impl constructed " << std::endl;
}
void test() {
}
~main_win_impl() {}
};

#endif

// now we're ready
# include "main_win_impl.h"
main_win_impl m_main_win_impl;

int main()
{
m_main_win_impl.test();
}

For starters, the m_rec object is declared as extern within msg_impl.h,
yet the compiler (.NET) complains that m_rec (commented out line -
below) is undefined.

// m_rec.update(*this);

The prime solution - assuming I understood correctly - is a
manager class. Source (helps me visualize better :)) sample on such a
class would be greatly appreaciated.

The prime objective is to get a feel for/have a globally accessible
m_rec object that I could access - in this case - in msg_impl.

Jul 23 '05 #1
0 1192

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

Similar topics

88
by: Tim Tyler | last post by:
PHP puts most of its functions into a big flat global namespace. That leads to short function names - but creates a namespace minefield for programmers. Lots of the functions are legacies from...
2
by: bb snowman | last post by:
Hi there, can anyone tell me how I can create a struture that is defined globally for several modules? I would like to do a configuration-struct that can be accessed from anywhere in my program....
7
by: Martin Stich | last post by:
hi, i want to redefine the global operator new for logging and stats purposes. is it a good idea to use malloc() as allocation function ? or should i call one of those weird crt functions....or...
2
by: Tim | last post by:
Please advise if you can. Presumably initialisation of members in member initialisation lists is perfomed by 'C' run-time startup. If the CRT was never started-up would those members be garbage?...
2
by: Thomas Matthews | last post by:
Hi, I'm getting linking errors when I declare a variable in the global scope, but not inside a function. The declarations are the same (only the names have been changed...). class Book {...
4
by: Krice | last post by:
Is it possible that construction of a global instance can fail? I'm suspecting this because the program seems to crash before main(). Is it a better practice to declare a pointer for the object...
7
by: John Ruiz | last post by:
the constructor definition in my Global.asax.cs file contains (among other things) the following line: System.Diagnostics.Debug.WriteLine( "Global Constructor ran." ); when I run my web...
8
by: Morpheus | last post by:
Hello, Say I have a class with a member... char mId; Whenever an object is created, I want to assign an incrementing character to this member, for instance the first would be A, then B, C,...
2
by: mars | last post by:
In my application, global variable A, during its construction, depends on another global variable, say B. However, variable B may have not been initialized by then. How can I make sure that...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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: 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.