Sziasztok!
#include < vector >
using std::vector;
template < class T, template < typename > class C >
class P
{
C < T > data;
};
int main()
{
P < float,std::vector > p;
}
fordítása :
$ g++-4.1 -Wall -pedantic -o p proba2.cxx
$ g++-4.3 -Wall -pedantic -o p proba2.cxx
proba2.cxx: In function ‘int main()’:
proba2.cxx:26: error: type/value mismatch at argument 2 in template parameter list for ‘template < class T, template < class > class C > class P’
proba2.cxx:26: error: expected a template of type ‘template < class > class C’, got ‘template < class _Tp, class _Alloc > class std::vector’
proba2.cxx:26: error: invalid type in declaration before ‘;’ token
proba2.cxx:26: warning: unused variable ‘p’
Azaz 4.1 -essel lefordul, 4.3-al nem. Kitaláltam azonban rá egy megoldást, de ez nem platformfüggetlen hiszen az STL-es konténerek 2+ tpl paramétert várnak :
#include < vector >
using std::vector;
template < class T, template < typename T,typename A = std::allocator < T > > class C >
class P
{
C < T > data;
};
int main()
{
P < float,std::vector > p;
}
$ g++-4.3 -Wall -pedantic -o p proba2.cxx
$ g++-4.1 -Wall -pedantic -o p proba2.cxx
[code]
És a kérdés: Miért? Az első megoldás eddig olyan szépen működött.
- 1299 megtekintés
Hozzászólások
A 4.2-es release-ben vették ki:
The (undocumented) extension which permitted templates with
default arguments to be bound to template template parameters with
fewer parameters has been removed. For example:
template <template <typename> class C>
void f(C<double>) {}
template <typename T, typename U = int>
struct S {};
template void f(S<double>);
is no longer accepted by G++. The reason this code is not
accepted is that S
is a template with two parameters;
therefore, it cannot be bound to C
which has only
one parameter.
KisKresz
- A hozzászóláshoz be kell jelentkezni
áhááá, köszi
- A hozzászóláshoz be kell jelentkezni