如何传递此模板模板参数? (MSVC ++ 8错误C3200) [英] How to pass this template template argument? (MSVC++ 8 error C3200)

查看:64
本文介绍了如何传递此模板模板参数? (MSVC ++ 8错误C3200)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下尝试传递我的模板Base作为模板模板

参数被Microsoft VC ++ 8.0(2005)拒绝,而它在VC ++ 7.1(2003)上仍然可以工作
。它是正确的C ++吗?是否有解决方法?


模板< typename T> class Base

{

};

template< typename U,template< typename> class TempTemp>

class Derived;


template< typename V>

class Derived< V,Base> :public Base< V>

{

public:

template< typename W> void Fun(派生< W,Base>&)//< - 错误!?!

{

}

};


MSVC ++ 8.0说有趣(Derived< W,Base>&):

错误C3200:''Base< T>'':模板无效模板的参数

参数''TempTemp'',期望一个类模板

参见类模板实例化''Derived< V,Base>''是

编译

亲切的问候,


Niels Dekker
www.xs4all.nl/~nd/dekkerware

The following attempt to pass my template "Base" as a template template
argument was rejected by Microsoft VC++ 8.0 (2005), while it still works
on VC++ 7.1 (2003). Is it correct C++? And is there a workaround?

template <typename T> class Base
{
};
template <typename U, template <typename> class TempTemp>
class Derived;

template <typename V>
class Derived<V, Base> : public Base<V>
{
public:
template <typename W> void Fun(Derived<W, Base>&) // <-- error!?!
{
}
};

MSVC++ 8.0 says about Fun(Derived<W, Base>&):
error C3200: ''Base<T>'' : invalid template argument for template
parameter ''TempTemp'', expected a class template
see reference to class template instantiation ''Derived<V,Base>'' being
compiled
Kind regards,

Niels Dekker
www.xs4all.nl/~nd/dekkerware

推荐答案

Niels Dekker - 没有回复地址写道:
Niels Dekker - no reply address wrote:
以下尝试传递我的模板Base作为模板
模板参数被Microsoft VC ++ 8.0(2005)拒绝,而它仍然适用于VC ++ 7.1(2003)。它是正确的C ++吗?是否有一个
解决方法?

模板< typename T> class Base
{
};
template< typename U,template< typename> class TempTemp>
class Derived;

template< typename V>
class Derived< V,Base> :public Base< V>
{
公开:
模板< typename W> void Fun(Derived< W,Base>&)//< - 错误!?!
{
}
};

MSVC ++ 8.0说的关于Fun(Derived< W,Base>&):
错误C3200:''Base< T>'':模板
参数''TempTemp''的模板参数无效,需要一个类模板
参见类模板实例化''派生< V,Base>''正在编译
The following attempt to pass my template "Base" as a template
template argument was rejected by Microsoft VC++ 8.0 (2005), while it
still works on VC++ 7.1 (2003). Is it correct C++? And is there a
workaround?

template <typename T> class Base
{
};
template <typename U, template <typename> class TempTemp>
class Derived;

template <typename V>
class Derived<V, Base> : public Base<V>
{
public:
template <typename W> void Fun(Derived<W, Base>&) // <-- error!?!
{
}
};

MSVC++ 8.0 says about Fun(Derived<W, Base>&):
error C3200: ''Base<T>'' : invalid template argument for template
parameter ''TempTemp'', expected a class template
see reference to class template instantiation ''Derived<V,Base>'' being
compiled




我刚添加了这个:


int main()

{

派生< int,Base> di;

派生< char,Base> dc;

di.Fun(dc);

}


使用VC ++ v8.0成功编译它。 />

如果您希望我们能够帮助您解决任何特定问题,请下次发送_complete_代码。


V



I just added this:

int main()
{
Derived<int,Base> di;
Derived<char,Base> dc;
di.Fun(dc);
}

And compiled it successfully with VC++ v8.0.

Please next time post the _complete_ code if you want us to be able
to help you with any particular problem.

V


" Victor Bazarov" <五******** @ comAcast.net>在消息中写道

新闻:EZ ******************** @ comcast.com
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:EZ********************@comcast.com
Niels Dekker - 没有回复地址写道:
Niels Dekker - no reply address wrote:
以下尝试传递我的模板Base作为模板
模板参数被Microsoft VC ++ 8.0(2005)拒绝,而它仍然适用于VC ++ 7.1(2003)。它是正确的C ++吗?是否有一个
解决方法?

模板< typename T> class Base
{
};
template< typename U,template< typename> class TempTemp>
class Derived;

template< typename V>
class Derived< V,Base> :public Base< V>
{
公开:
模板< typename W> void Fun(Derived< W,Base>&)//< - 错误!?!
{
}
};

MSVC ++ 8.0说的关于Fun(Derived< W,Base>&):
错误C3200:''Base< T>'':模板
参数''TempTemp''的模板参数无效,需要一个类模板
参见类模板实例化''Derived< V,Base>''
正在编译
The following attempt to pass my template "Base" as a template
template argument was rejected by Microsoft VC++ 8.0 (2005), while it
still works on VC++ 7.1 (2003). Is it correct C++? And is there a
workaround?

template <typename T> class Base
{
};
template <typename U, template <typename> class TempTemp>
class Derived;

template <typename V>
class Derived<V, Base> : public Base<V>
{
public:
template <typename W> void Fun(Derived<W, Base>&) // <-- error!?!
{
}
};

MSVC++ 8.0 says about Fun(Derived<W, Base>&):
error C3200: ''Base<T>'' : invalid template argument for template
parameter ''TempTemp'', expected a class template
see reference to class template instantiation ''Derived<V,Base>''
being compiled



我刚添加了这个:

int main()
{
Derived< int,Base> di;
Derived< char,Base> dc;
di.Fun(dc);
}
用VC ++ v8.0成功编译它。



I just added this:

int main()
{
Derived<int,Base> di;
Derived<char,Base> dc;
di.Fun(dc);
}

And compiled it successfully with VC++ v8.0.



奇怪。在VC ++ Express 2005或者发布

VS Team System的候选人时,它不会为我编译。


-

John Carson


Strange. It won''t compile for me on either VC++ Express 2005 or a Release
Candidate of VS Team System.

--
John Carson


" Niels Dekker - 没有回复地址 <未***** @ this.is.invalid>写在

消息新闻:43 *************** @ this.is.invalid
"Niels Dekker - no reply address" <un*****@this.is.invalid> wrote in
message news:43***************@this.is.invalid
以下尝试传递我的模板"基地"作为模板
模板参数被Microsoft VC ++ 8.0(2005)拒绝,而它仍然适用于VC ++ 7.1(2003)。它是正确的C ++吗?是否有一个
解决方法?

模板< typename T> class Base
{
};
template< typename U,template< typename> class TempTemp>
class Derived;

template< typename V>
class Derived< V,Base> :public Base< V>
{
公开:
模板< typename W> void Fun(Derived< W,Base>&)//< - error!?!
{
}
};
The following attempt to pass my template "Base" as a template
template argument was rejected by Microsoft VC++ 8.0 (2005), while it
still works on VC++ 7.1 (2003). Is it correct C++? And is there a
workaround?

template <typename T> class Base
{
};
template <typename U, template <typename> class TempTemp>
class Derived;

template <typename V>
class Derived<V, Base> : public Base<V>
{
public:
template <typename W> void Fun(Derived<W, Base>&) // <-- error!?!
{
}
};




解决方法是使用::来限定Base,使其成为:


模板< typename W> void Fun(Derived< W,:: Base>&)

{

}


至于您的原始代码是有效的C ++,我倾向于认为

它是,但我不打赌我的生活。

原始代码有效的最强显示是Comeau无怨无悔地编译它。


我相信发生的事情如下。 VC ++ 8读取Base为

Base< V>。在下面的更简单的例子中,这是正确的:


模板< class V>

class Base

{

基数b; //将其读作Base< V>

};


如果你想在Base中引用模板Base,那么你可以使用

::基础。


VC ++ 8似乎已经出现了微妙的错误就是在处理Base中

派生的方式与它相同对待基地。因为Base是一个

依赖的基础(即,它取决于V),两个阶段查找(据我所知

它)说它不应该被查找直到模板被实例化。

因此Base< V>在定义Fun时没有看到,结果Base被

视为模板,因此代码编译。 VC ++不支持两阶段

查找,因此它确实看到Base< V>当定义Fun并因此给出一个

错误...或者至少我认为这是解释。

-

John Carson



The workaround is to qualify Base with ::, so that it becomes:

template <typename W> void Fun(Derived<W, ::Base>&)
{
}

As for whether your original code is valid C++, I am inclined to think that
it is but I wouldn''t bet my life on it. The strongest indication that the
original code is valid is that Comeau compiles it without complaint.

I believe what is happening is the following. VC++ 8 is reading Base as
Base<V>. In the following simpler example, that would be correct:

template <class V>
class Base
{
Base b; // read this as Base<V>
};

If you wanted to refer to the template Base inside Base, then you could use
::Base.

Where VC++ 8 appears to have gone subtlely wrong is in treating Base in
Derived the same way as it would treat Base in Base. Because Base is a
dependent base (i.e., it depends on V), two phase lookup (as I understand
it) says that it should not be looked up until the template is instantiated.
Thus Base<V> is not seen when Fun is defined, with the result that Base is
treated as a template, so the code compiles. VC++ does not support two phase
lookup, so it does see Base<V> when Fun is defined and hence gives an
error...or at least I think that is the explanation.
--
John Carson


这篇关于如何传递此模板模板参数? (MSVC ++ 8错误C3200)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆