template<typename T>
class Form
{
public:
staticint i;
Form()
{
i++;
cout << i << "\t";
}
~Form()
{
}
};
int Form::i=0;
i get an error on: int Form::i=0;
error message: "'template<class T> class Form' used without template parameters"
so how can i initilizate a template class static variable?
The output must be 2. But the Window2 is different, but the Form it is parent class. So how can i use a static variable on Form? The 'i' must be incremented when a child class is created
Sorry something
The output must be 2. But the Window2 is different, but the Form it is parent class. So how can i use a static variable on Form? The 'i' must be incremented when a child class is created
Form is not a class. Form is a class template.
Form<A> and Form<B> are completely distinct class types.
So how can i use a static variable on Form? The 'i' must be incremented when a child class is created
#include <iostream>
using std::cout;
externint i;
template <typename T>
class Form
{
public:
Form()
{
i++;
cout << i << "\t";
}
};
// in exactly one source file
int i;
class Window: public Form<Window> {}Window;
class Window2: public Form<Window2> {}Window2;
int main() {}
class Form
{
public:
staticinlineint FormCount=0;
Form()
{
FormCount++;
cout << FormCount << "\t";
}
};
class Window: public Form
{
}Window;
class Window2: public Form
{
}Window2;
int main()
{
return 0;
}
output:
1 2
compiler options must have, at least, -std=C++17 or -std=gnu++17.
the static variable must be 'inline'.
thanks for all to all
can i do these: typedefstaticinline Static;
?
error line:
" 'Static' does not name a type; did you mean 'static'?"
update: ate least, i can use macros: #define Static static inline
PS: never use ';' after a macro hehehehe(not increment, just the 1st time hehehehe)
thank you so much