I'm trying to create static constant that will be named the same in different classes and can be accessed from other classes
I'm trying to access to the constant from other classes like that B::num
My code:
main.cpp
...
Ptr ptr;
A *a = C::make(ptr);
A.h
class A { //pure virtual
public:
virtual void func()=0;
virtual void func2()=0;
protected:
Ptr ptr;
}
B.h
class B : public A {
public:
B();
static unsigned char const num[2];
...
}
B.cpp
#include "B.h"
constexpr unsigned char B::num[]={0x4,0x5};
B::B(){..}
C.h
#include "A.h"
#include "B.h"
class C {
public:
static A* make(const Ptr &);
}
C.cpp
A *C::make(const Ptr &ptr){
if(!memcmp(ptr.memory,B::num,sizeof(B::num))){
...
}
}
errors
B.h file - error: from previous declaration 'B::num'
B.cpp file - error: redeclaration B::num differs in 'constexpr'
What is the problem? Thanks.