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

Problem with in-line "typedef" and class cross-reference. Need help.

Hi everybody,

I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.

=Do you know a way to solve this problem (keeping the types inside
the classes) ?

Thanks in advance.
Here is a simple source illustrating my problem :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::MyEnum);
typedef MyEnum { red, pink, blue };
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::MyEnum);
typedef MyEnum { one, two, three };
};

Aug 18 '06 #1
7 4680
fo*****@laposte.net wrote:
I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
>>MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.

=Do you know a way to solve this problem (keeping the types inside
the classes) ?
There is no way. So, as you "have to" but "cannot", you simply "don't
have to" any more. You must find some other solution, like pulling
both of those enums into a separate class or leave them at the namespace
level.

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 18 '06 #2
for....@laposte.net wrote:
Hi everybody,

I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.
If they "have to be", then you're stuck. You'll have to find another
job.
>
=Do you know a way to solve this problem (keeping the types inside
the classes) ?

Thanks in advance.
Here is a simple source illustrating my problem :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::MyEnum);
typedef MyEnum { red, pink, blue };
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::MyEnum);
typedef MyEnum { one, two, three };
};
Can't be done. You can forward declare an enum that is at
namespace/file scope, but not one at class scope (except inside the
classes definition, of course, but that doesn't apply here).

Cheers! --M

Aug 18 '06 #3
Thanks for the information.

To be more practical, we decided to use "boost::shared_ptr" smart
pointers instead of classic C++ pointers in a home-made API.
Consequently, all classes have a "#typedef boost::shared_ptr<APIObject>
Ptr" type definition in the class scope.

Unfortunately, when 2 classes are cross-referenced, this can not work.
As you said, I will have to find another way to do it.
mlimber a écrit :
for....@laposte.net wrote:
Hi everybody,

I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.

If they "have to be", then you're stuck. You'll have to find another
job.

=Do you know a way to solve this problem (keeping the types inside
the classes) ?

Thanks in advance.
Here is a simple source illustrating my problem :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::MyEnum);
typedef MyEnum { red, pink, blue };
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::MyEnum);
typedef MyEnum { one, two, three };
};

Can't be done. You can forward declare an enum that is at
namespace/file scope, but not one at class scope (except inside the
classes definition, of course, but that doesn't apply here).

Cheers! --M
Aug 18 '06 #4

fo*****@laposte.net wrote:
Hi everybody,

I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.

=Do you know a way to solve this problem (keeping the types inside
the classes) ?

Thanks in advance.
Here is a simple source illustrating my problem :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::MyEnum);
typedef MyEnum { red, pink, blue };
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::MyEnum);
typedef MyEnum { one, two, three };
};
Could you do something like:

// Abase.h
struct Abase
{
enum MyEnum { red, pink, blue } ;
} ;

// Bbase.h
struct Bbase
{
enum MyEnum { one, two, three } ;
} ;

// A.h
#include "Abase.h"
#include "Bbase.h"

class A : public Abase
{
public:
A(Abase::MyEnum) ;
} ;

// B.h
#include "Abase.h"
#include "Bbase.h"

class B : public Bbase
{
public:
B(Bbase::MyEnum) ;
} ;

--
Alan Johnson

Aug 18 '06 #5

Alan Johnson wrote:
fo*****@laposte.net wrote:
Hi everybody,

I have the following problem :

B class need A::MyEnum type and A class need B::MyEnum type.
In both case, the class type is incomplete so it is obvious that the
::MyEnum can not be found in the class definition (the compiler
complains)

My problem is the MyEnum types have to be defined inside the class
scopes.

=Do you know a way to solve this problem (keeping the types inside
the classes) ?

Thanks in advance.
Here is a simple source illustrating my problem :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::MyEnum);
typedef MyEnum { red, pink, blue };
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::MyEnum);
typedef MyEnum { one, two, three };
};

Could you do something like:

// Abase.h
struct Abase
{
enum MyEnum { red, pink, blue } ;
} ;

// Bbase.h
struct Bbase
{
enum MyEnum { one, two, three } ;
} ;

// A.h
#include "Abase.h"
#include "Bbase.h"

class A : public Abase
{
public:
A(Abase::MyEnum) ;
} ;

// B.h
#include "Abase.h"
#include "Bbase.h"

class B : public Bbase
{
public:
B(Bbase::MyEnum) ;
} ;
Sorry, I got the parameters to the constructors backwards, but you get
the idea.

--
Alan Johnson

Aug 18 '06 #6
Thanks very much for the idea of the base classes.

In facts, my first sample was enough specific to describe my problem.

I should have wrote it this way :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::Ptr);
typedef boost::shared_ptr<APtr;
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::Ptr);
typedef boost::shared_ptr<BPtr;
};

.... where A::Ptr point to A class and B::Ptr point to B class (smart
pointers replace the classic C pointers)

This sample works with C pointers but not with Smart Pointers because
of the class cross-reference.
Alan Johnson a écrit :

// Abase.h
struct Abase
{
enum MyEnum { red, pink, blue } ;
} ;

// Bbase.h
struct Bbase
{
enum MyEnum { one, two, three } ;
} ;

// A.h
#include "Abase.h"
#include "Bbase.h"

class A : public Abase
{
public:
A(Abase::MyEnum) ;
} ;

// B.h
#include "Abase.h"
#include "Bbase.h"

class B : public Bbase
{
public:
B(Bbase::MyEnum) ;
} ;
Sorry, I got the parameters to the constructors backwards, but you get
the idea.
Aug 21 '06 #7
Thanks very much for the idea of the base classes.

In facts, my first sample was not enough specific to describe my
problem.
I should have wrote it this way :

---------------------------------------

#include "B.h"

class B;

class A
{
public: A(B::Ptr);
typedef boost::shared_ptr<APtr;
};

---------------------------------------

#include "A.h"

class A;

class B
{
public: B(A::Ptr);
typedef boost::shared_ptr<BPtr;
};
.... where A::Ptr point to A class and B::Ptr point to B class (smart
pointers replace the classic C pointers)

This sample works with C pointers but not with Smart Pointers because
of the class cross-reference.
Alan Johnson a écrit :

// Abase.h
struct Abase
{
enum MyEnum { red, pink, blue } ;
} ;

// Bbase.h
struct Bbase
{
enum MyEnum { one, two, three } ;
} ;

// A.h
#include "Abase.h"
#include "Bbase.h"

class A : public Abase
{
public:
A(Abase::MyEnum) ;
} ;

// B.h
#include "Abase.h"
#include "Bbase.h"

class B : public Bbase
{
public:
B(Bbase::MyEnum) ;
} ;
Sorry, I got the parameters to the constructors backwards, but you get
the idea.
Aug 21 '06 #8

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

Similar topics

11
by: Aing | last post by:
Anyone knows what can be cause of this problem? //////////////////////////////////////////////////////////// typedef struct _date_struct { int date,month,year; }date_struct; Class Date {...
1
by: A. Saksena | last post by:
Hi all, I am trying to compile following code :- ======================================= #include <iostream.h> #include <string> namespace tlm { template <typename REQUEST, typename RESPONSE >...
12
by: Generic Usenet Account | last post by:
Is it that I am blurry eyed, or is it indeed that the C++ string class has no tokenizer method defined? I have defined my own functions , but I would prefer to use the standard functions, if...
0
by: Olaf Petzold | last post by:
Hi, the following code fragment doesn't compile: ----8<------ #include <iostream> template<class T, std::size_t Sz>
5
by: Joe Pizzi | last post by:
Is there any difference between the following two definitions? If so, can you explain them to me? typedef volatile struct { int x; } VS_Def; typedef struct {
11
by: Donkeylung | last post by:
I have a base class which has a protected member: map<mstring,mstring> mstring is a derived class from std::string, which includes some functionality to cope with MFC. It works fine in the base...
15
by: fungus | last post by:
I'm moving some code from VC++ 6 to VC++ 2005 and I've run into a nasty problem because iterators are no longer pointers. In the program I'm moving, there's a std::vector of items hidden inside...
3
by: toton | last post by:
Hi, Is it possible to have a class level namespace opening instead of file level . Something like this, I have a long namespace like namespace com { namespace my_company{ namespace...
5
by: Jess | last post by:
Hello, I've seen two forms of template declarations template<typename T> class A{...}; and template<class T>
3
by: jimhce | last post by:
Hi, How can a child class passes its non-static member function to the parent class? class A { public: typedef void *(*object_t)(void *); A(object_t f) : func(f) {} virtual ~A(){}...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
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,...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.