Home > Archive > VC STL > August 2005 > template template support
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
template template support
|
|
| nguyenxuanson@gmail.com 2005-08-24, 7:02 pm |
| I just try the example of section 8.3.4 in the book "C++ templates: the
complete guide". The following code should work (as mentioned in the
book) but when I tried to compile, I get the error C2976 which
high-light the lines which define the private variable "dom1" and
"dom2".
Can someone explains to me this problem?
Thanks
XS
====================================
#include <list>
#include <memory>
// declares:
// namespace std {
// template <typename T,
// typename Allocator = allocator<T> >
// class list;
// }
template<typename T1,
typename T2,
template<typename T,
typename = std::allocator<T> > class Container>
// Container now accepts standard container templates
class Relation {
public:
private:
Container<T1> dom1;
Container<T2> dom2;
};
int main()
{
Relation<int, double, std::list> rel;
}
| |
| Doug Harrison [MVP] 2005-08-24, 7:02 pm |
| On 24 Aug 2005 16:06:07 -0700, nguyenxuanson@gmail.com wrote:
>I just try the example of section 8.3.4 in the book "C++ templates: the
>complete guide". The following code should work (as mentioned in the
>book) but when I tried to compile, I get the error C2976 which
>high-light the lines which define the private variable "dom1" and
>"dom2".
>Can someone explains to me this problem?
>Thanks
>XS
>====================================
>#include <list>
>#include <memory>
> // declares:
> // namespace std {
> // template <typename T,
> // typename Allocator = allocator<T> >
> // class list;
> // }
>template<typename T1,
> typename T2,
> template<typename T,
> typename = std::allocator<T> > class Container>
> // Container now accepts standard container templates
>class Relation {
> public:
> private:
> Container<T1> dom1;
> Container<T2> dom2;
>};
>int main()
>{
> Relation<int, double, std::list> rel;
>}
Looks like VC7.1 doesn't fill in the default argument for Container. Try
specifying the allocator in the declarations of dom1 and dom2. This appears
to be fixed in the upcoming VC++ 2005.
--
Doug Harrison
VC++ MVP
| |
| nguyenxuanson@gmail.com 2005-08-24, 7:02 pm |
| even when I filled in manually, things does not work as well. On the
other hand, the g++ compile everything (erroneous as well:)
So, this is a problem with VC7.1?
XS
| |
| Doug Harrison [MVP] 2005-08-24, 7:02 pm |
| On 24 Aug 2005 16:43:02 -0700, nguyenxuanson@gmail.com wrote:
>even when I filled in manually, things does not work as well. On the
>other hand, the g++ compile everything (erroneous as well:)
>So, this is a problem with VC7.1?
Did you give a name to Container's second template argument, e.g. change:
template<typename T,
typename = std::allocator<T> > class Container
to:
template<typename T,
typename U = std::allocator<T> > class Container
Then it should work when you supply all the template arguments in the domN
declarations.
--
Doug Harrison
VC++ MVP
| |
| nguyenxuanson@gmail.com 2005-08-25, 8:02 am |
| thank, that's work.
XS
|
|
|
|
|