in file someclass.h
#ifndef some_class_h_ #define some_class_h_ #include <iostream> using std::cout; using std::endl; template <class t, class p> class someclass { public: someclass(); void somemethod(); protected: typedef unsigned int heapposition; heapposition somevariable; private: static const heapposition nullposition; }; template <class t, class p> const typename someclass<t,p>::heapposition someclass<t,p>::nullposition = -1; template <class t, class p> someclass<t,p>::someclass(){} template <class t, class p> void someclass<t,p>::somemethod() { somevariable=nullposition; cout<<"nullposition:"<<nullposition<<endl; } #endif
in file main.cpp
#include <cstdlib> #include <iostream> #include "someclass.h" using namespace std; int main(int argc, char *argv[]) { someclass<int,int> someclass; someclass.somemethod(); system("pause"); return exit_success; }
basically have templated class static const member (nullposition)
. have tried inizialitazion of of class, both outside class definition , inline in
static const heapposition nullposition=-1;
when declaring member.
however, in both cases, when reference in somemethod
its values random value - i.e. has not been initialized.
i have done type of thing many other times, , have never had type of problem.
what doing wrong?
can please me? thank in advance time.
thanks, gerald celente
are sure random value? have declared nullposition
unsigned
, assigning -1
cause cout.operator<<
(invoked in unsigned
overload) print large value (4294967295
32bit int
)
Comments
Post a Comment