L
Leslaw Bieniasz
Hello,
I have the following problem:
file a.h ---------------
template <class T>
class A
{
// some stuff
};
template class A<float>;
template class A<double>;
file b.h ---------------
template <class T>
class B
{
// some stuff
private:
static A<T> A_static;
};
// ???
template class B<float>;
template class B<double>;
--------------------------
My question is:
according to the rules of C++, static data member A_static of B
has to be additionally defined (and initialised) outside the class
declaration of B, otherwise we get linker errors (missing external).
What exactly should I do, and where should I put such a definition of
A_static? I note that template class A does not actually require any
initialisation, because operations on A_static are supposed
to take place later during the program run.
My attempt to place the statement:
template <class T> A<T> B<T>::A_static;
in the place indicated by three question marks produces
linker warnings stating that variable A_static is defined
twice; once in the module for B, and once in the module that calls
b.h (which is a quite understandable, but unwanted effect).
The problem does not seem to arise if A_static is not a class
instance, but some built-in type, like, for example
static int A_static;
Then a statement
template <class T> int B<T>::A_static = 1;
placed in the line with three question marks works fine.
If this plays any role, I am using Borland C++ Builder 6.0.
L.B.
*-------------------------------------------------------------------*
| Dr. Leslaw Bieniasz, |
| Institute of Physical Chemistry of the Polish Academy of Sciences,|
| Department of Electrochemical Oxidation of Gaseous Fuels, |
| ul. Zagrody 13, 30-318 Cracow, Poland. |
| tel./fax: +48 (12) 266-03-41 |
| E-mail: (e-mail address removed) |
*-------------------------------------------------------------------*
| Interested in Computational Electrochemistry? |
| Visit my web site: http://www.cyf-kr.edu.pl/~nbbienia |
*-------------------------------------------------------------------*
I have the following problem:
file a.h ---------------
template <class T>
class A
{
// some stuff
};
template class A<float>;
template class A<double>;
file b.h ---------------
template <class T>
class B
{
// some stuff
private:
static A<T> A_static;
};
// ???
template class B<float>;
template class B<double>;
--------------------------
My question is:
according to the rules of C++, static data member A_static of B
has to be additionally defined (and initialised) outside the class
declaration of B, otherwise we get linker errors (missing external).
What exactly should I do, and where should I put such a definition of
A_static? I note that template class A does not actually require any
initialisation, because operations on A_static are supposed
to take place later during the program run.
My attempt to place the statement:
template <class T> A<T> B<T>::A_static;
in the place indicated by three question marks produces
linker warnings stating that variable A_static is defined
twice; once in the module for B, and once in the module that calls
b.h (which is a quite understandable, but unwanted effect).
The problem does not seem to arise if A_static is not a class
instance, but some built-in type, like, for example
static int A_static;
Then a statement
template <class T> int B<T>::A_static = 1;
placed in the line with three question marks works fine.
If this plays any role, I am using Borland C++ Builder 6.0.
L.B.
*-------------------------------------------------------------------*
| Dr. Leslaw Bieniasz, |
| Institute of Physical Chemistry of the Polish Academy of Sciences,|
| Department of Electrochemical Oxidation of Gaseous Fuels, |
| ul. Zagrody 13, 30-318 Cracow, Poland. |
| tel./fax: +48 (12) 266-03-41 |
| E-mail: (e-mail address removed) |
*-------------------------------------------------------------------*
| Interested in Computational Electrochemistry? |
| Visit my web site: http://www.cyf-kr.edu.pl/~nbbienia |
*-------------------------------------------------------------------*