473,782 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4720
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_p tr<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_p tr<APtr;
};

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

#include "A.h"

class A;

class B
{
public: B(A::Ptr);
typedef boost::shared_p tr<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_p tr<APtr;
};

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

#include "A.h"

class A;

class B
{
public: B(A::Ptr);
typedef boost::shared_p tr<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
2065
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 { private : date_struct m_data;
1
2344
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 > class tlm_transport_if {
12
2619
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 available. Thanks Bhat
0
1457
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
6649
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
4325
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 class, but when I try to use it in a derived class, it gives me an error message. C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7\include\functional(139): error C2678: binary '<' : no operator
15
2185
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 a class and users of the class get to iterate it via a const_iterator. eg.
3
1821
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 my_project{ namespace parser{ class my_parser{ };
5
425
by: Jess | last post by:
Hello, I've seen two forms of template declarations template<typename T> class A{...}; and template<class T>
3
2542
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(){} private:
0
9639
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
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10308
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
9939
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5507
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4040
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
3633
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.