A
Adrian Hawryluk
Can one define a partial class (first part containing constants like
enums) and then define the rest of the class elsewhere?
I ask this because I've had in the past needed to defined two classes
(call them A and B), each dependent upon the other. Class A requires
the enum type defined in Class B. An example follows:
<header file="A.h">
#if !defined A_H
# define A_H
// Stub for forward referencing
class A;
# include “B.h”
class A
{
// Interface functions
void f(B* b, B::b_e enums);
...
};
#endif
</header>
<header file="B.h">
#if !defined B_H
# define B_H
// Stub for forward referencing
class B;
# include “A.h”
class B
{
public:
enum b_e { enum1, enum2 };
// Interface functions
...
};
#endif
</header>
The only way I see around this are:
1. Declare a public base class for B that contains the enums. It is not
dependent on A so no problem occurs. It would be declared with the
class B stub;
2. Declare the enums outside of class scope, removing the dependency
lock. It would be declared with the class B stub;
3. Make a faux template class, making the class a stub. Haven't tried
this.
Problems for each are:
1. Base classes would have a explicit size of 1, adding a small amount
of overhead.
2. Enum is not scoped to a class.
3. A bit overkill if it does work.
Any thoughts?
Adrian
--
========================================================
Adrian Hawryluk BSc. Computer Science
--------------------------------------------------------
Specialising in: OOD Methodologies in UML
OOP Methodologies in C, C++ and more
RT Embedded Programming
__------------------------------------------------__
-----[blog: http://adrians-musings.blogspot.com/]-----
'------------------------------------------------------'
This content is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 License
http://creativecommons.org/licenses/by-nc-sa/3.0/
=========================================================
enums) and then define the rest of the class elsewhere?
I ask this because I've had in the past needed to defined two classes
(call them A and B), each dependent upon the other. Class A requires
the enum type defined in Class B. An example follows:
<header file="A.h">
#if !defined A_H
# define A_H
// Stub for forward referencing
class A;
# include “B.h”
class A
{
// Interface functions
void f(B* b, B::b_e enums);
...
};
#endif
</header>
<header file="B.h">
#if !defined B_H
# define B_H
// Stub for forward referencing
class B;
# include “A.h”
class B
{
public:
enum b_e { enum1, enum2 };
// Interface functions
...
};
#endif
</header>
The only way I see around this are:
1. Declare a public base class for B that contains the enums. It is not
dependent on A so no problem occurs. It would be declared with the
class B stub;
2. Declare the enums outside of class scope, removing the dependency
lock. It would be declared with the class B stub;
3. Make a faux template class, making the class a stub. Haven't tried
this.
Problems for each are:
1. Base classes would have a explicit size of 1, adding a small amount
of overhead.
2. Enum is not scoped to a class.
3. A bit overkill if it does work.
Any thoughts?
Adrian
--
========================================================
Adrian Hawryluk BSc. Computer Science
--------------------------------------------------------
Specialising in: OOD Methodologies in UML
OOP Methodologies in C, C++ and more
RT Embedded Programming
__------------------------------------------------__
-----[blog: http://adrians-musings.blogspot.com/]-----
'------------------------------------------------------'
This content is licensed under the Creative Commons
Attribution-Noncommercial-Share Alike 3.0 License
http://creativecommons.org/licenses/by-nc-sa/3.0/
=========================================================