473,839 Members | 1,362 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

boost::shared_p tr mutual header inclusion problem

Hi

I've the following header problem that I need two classes to know each
other through a boost::shared_p tr. Does any of you smart guys have a
solution?

A.h
----------------------
#include "B.h"

Class A
{
public:
typedef boost::shared_p tr< A > SharedPtr;
void foo( B::SharedPtr& _b) {};
private:
B::SharedPtr b;

}

B.h
-------------------------
#include "A.h"

Class B
{
public:
typedef boost::shared_p tr< B > SharedPtr;
void foo( A::SharedPtr& _a) {};
private:
A::SharedPtr a;
}

Best Regards
Dennis Nielsen

Jan 5 '06 #1
2 4840

krema2ren wrote:
Hi

I've the following header problem that I need two classes to know each
other through a boost::shared_p tr. Does any of you smart guys have a
solution?

A.h
----------------------
#include "B.h"

Class A
{
public:
typedef boost::shared_p tr< A > SharedPtr;
void foo( B::SharedPtr& _b) {};
private:
B::SharedPtr b;

}

B.h
-------------------------
#include "A.h"

Class B
{
public:
typedef boost::shared_p tr< B > SharedPtr;
void foo( A::SharedPtr& _a) {};
private:
A::SharedPtr a;
}


Don't use the typedef, and instead use forward class declaration, and
remove the #include

class A; //forward class declaration

class B
{
public:
void foo( boost::shared_p tr< A >& _a);// {};//Should move
implementation to source file for this method
private:
boost::shared_p tr< A > a;
};

FYI:
You should avoid using underscore prefix for your variable names,
because it can make your code non-portable. IAW C++ standard, variable
names that begin with an underscore are reserved for the
implementation.

Jan 5 '06 #2

Axter wrote:
Don't use the typedef, and instead use forward class declaration, and
remove the #include

class A; //forward class declaration

class B
{
public:
void foo( boost::shared_p tr< A >& _a);// {};//Should move
implementation to source file for this method
private:
boost::shared_p tr< A > a;
};


You can also get around the problem by adding a fwd.h header for your
classes. You can also write your own forward class for boost
shared_ptr. Thus:

// boost_spfwd.h
namespace boost
{
template< typename T > shared_ptr;
tempalte < typename T > scoped_ptr;
}

..// afwd.h

#include boost_spfwd.h
class A;
typedef boost::shared_p tr< A > A_Ptr;
typedef boost::shared_p tr< const A > A_CPtr;
typedef boost::scoped_p tr< const A > A_ScopedPtr;

// etc and choose your own naming convention.

Of course it goes without saying you use all the correct file guards.

Jan 5 '06 #3

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

Similar topics

4
3155
by: Philippe Guglielmetti | last post by:
I just ported old (VC6) working code to VC7.1 and have trouble with something like: class A; // forward typedef boost::smart_ptr<A> Aptr; class B{ Aptr a; virtual ~B(); // implemented after A has been defined };
5
2924
by: ctick | last post by:
Are there any advantages of using boost::shared_ptr other than auto_ptr from standard library?
6
9065
by: Ryan Mitchley | last post by:
Hi all Given bool bResult; shared_ptr<cSampleData> pNewData; shared_ptr<cBase> pNewBase; where cSampleData is descended from cBase, the following gives me a valid pNewData to the correct type:
2
2140
by: adebaene | last post by:
Hello group, There seems to be a bug int the interop layer in VC2005 when dealing with certain pointer types (or values?) Here is a repro case using Boost version 1.32 and C++/CLI : using namespace System; #pragma unmanaged
6
4043
by: Toby Bradshaw | last post by:
Hi, Consider the following: class A { public: virtual bool foo() = 0; };
5
2919
by: Jun | last post by:
Hello, I've code like : =========================================== class A{ public : // create print content friend std::ostream& operator<< (std::ostream& os, const A& a);
4
3965
by: EnsGabe | last post by:
Suppose you have a class heirarchy as such: class Base{ .... }; class Mid1 : public Base{ ....
0
1581
by: phlip | last post by:
Nick Keighley wrote: CC'd to the correct newsgroup. Yes, the destructor of the shared pointer will delete the object. Then its former address will convert to a reference. At some point - possibly the conversion - Undefined Behavior will begin. And then when whoever collects the reference uses it, Undefined Behavior will continue.
10
11640
by: tradevol | last post by:
Hi, I am playing with boost pointer and try to wrap the following codes A* func(){ ... if(condition 1 ){ return a; } else
0
9856
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
10910
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10589
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10654
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7021
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5683
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5867
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4493
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4066
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.