Topic: aggregate error on static constants of class template
Author: kes@omni.cc.purdue.edu (Thomas Kesler)
Date: 1999/03/01 Raw View
/*
I am stumbling toward an understanding of class templates.
While trying to convert a class on rational numbers to a class template, I
experienced diffulty coding static constants that would hold rational zero and
one in the int and long int formats. Below is code that reproduces the error
without it appearing in the large class rational. The aggregate error appears
to be flagging the two definitions in function main().
This code has been tested on 3 C++ compilers:
Borland C++ V5.3: compiles with no error
egcs: aggregate error
GNU C++ 2.8.1: aggregate error
I am trying to understand section 14.7.1 of the standard. With a standard in
place, should not all 3 compilers yield the same result?
Perhaps I am missing a very basic point about class templates. Neither the FAQ
of this news group and of two others nor my four feet of C++ books offers help.
*/
#include <iostream.h>
template< class T >
class R {
private:
int value;
public:
R ( int n ) : value( n ) { }
static const R< T > sobj;
};
template< class T >
const R< T > R< T >::sobj( 5 );
int main( ) {
R<int> x(1); //ERR: 'aggregate ... has incomplete type and cannot be init-z'
R<long int> y(2); // same error
return 0;
}
--
Thomas E. Kesler
PUCC, MATH-B88
765-496-8281
kes@purdue.edu
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]