F
Frank Bergemann
Hi,
i have a problem with applying CRTP.
Here is a short example, which demonstrate it:
========= base.h ==========
template <typename TYPE>
class Base
{
public:
Base()
{ /* void */ }
virtual ~Base()
{ /* void */ }
char buff[TYPE::MAX - TYPE::MIN + 1];
};
========== test.cc ==========
#include "base.h"
class Sample : public Base<Sample>
{
public:
Sample()
: Base<Sample>()
{ /* void */ }
~Sample()
{ /* void */ }
typedef enum {
MIN = 0,
MAX = 10
} Internal_t;
};
int main(int, char**)
{
return 0;
}
-----------------------------------------------
Compilation raises an error:
frank@charlie:~/TEST$ /usr/bin/g++ -o test test.cc
base.h: In instantiation of 'Base<Sample>':
test.cc:5: instantiated from here
base.h:13: error: incomplete type 'Sample' used in nested name
specifier
base.h:13: error: incomplete type 'Sample' used in nested name
specifier
base.h:13: error: array bound is not an integer constant
I could do a workaround and switch to std::vector<char> and allocate
in c'tor via some Sample::getSize().
But i wonder, if there is really no way to use the enum values in the
template base class?
(and if so: why?)
- many thanks!
rgds,
Frank
i have a problem with applying CRTP.
Here is a short example, which demonstrate it:
========= base.h ==========
template <typename TYPE>
class Base
{
public:
Base()
{ /* void */ }
virtual ~Base()
{ /* void */ }
char buff[TYPE::MAX - TYPE::MIN + 1];
};
========== test.cc ==========
#include "base.h"
class Sample : public Base<Sample>
{
public:
Sample()
: Base<Sample>()
{ /* void */ }
~Sample()
{ /* void */ }
typedef enum {
MIN = 0,
MAX = 10
} Internal_t;
};
int main(int, char**)
{
return 0;
}
-----------------------------------------------
Compilation raises an error:
frank@charlie:~/TEST$ /usr/bin/g++ -o test test.cc
base.h: In instantiation of 'Base<Sample>':
test.cc:5: instantiated from here
base.h:13: error: incomplete type 'Sample' used in nested name
specifier
base.h:13: error: incomplete type 'Sample' used in nested name
specifier
base.h:13: error: array bound is not an integer constant
I could do a workaround and switch to std::vector<char> and allocate
in c'tor via some Sample::getSize().
But i wonder, if there is really no way to use the enum values in the
template base class?
(and if so: why?)
- many thanks!
rgds,
Frank