模板相关查询 [英] template related query

查看:70
本文介绍了模板相关查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模板化的班级成员函数,呼叫临时成员

另一个班级的功能。


//啊

模板< class T>

A级{

公开:

静态T * create();

};


// Bh

B级{


模板< class T>

T * makeData();


};


模板< class T>

T * B :: makeData()

{

返回A< T> :: create();

}


当我在某些X.cpp中包含Bh时,我得到一个编译错误(gcc 3.3.6)。

(错误在我包含的行上,而不是我实例化的地方) 。


但是我没有得到gcc 4.2.2的编译错误。有什么方法我可以在gcc3.3.6中避免这个错误吗?


问候,

~Soumen

I''ve a templatized class member function calling templatized member
function of another class.

//A.h
template <class T>
class A {
public:
static T* create();
};

//B.h
class B {

template<class T>
T* makeData();

};

template<class T>
T* B::makeData()
{
return A<T>::create();
}

I get a compile error (gcc 3.3.6) when I include B.h in some X.cpp.
(Error is on the line where I include, not where I instantiate).

But I don''t get compile error with gcc 4.2.2. Is there any way that I
can avoid this error in gcc3.3.6?

Regards,
~ Soumen

推荐答案

10月10日,6:22 * pm,Soumen< soume ... @ gmail.comwrote:
On Oct 10, 6:22*pm, Soumen <soume...@gmail.comwrote:

我有一个模板化的班级成员函数,呼叫临时成员

另一个班级的功能。


//啊啊

模板< class T>

A级{

public:

static T * * * * create(); < br $>

};


// Bh

B级{

公开:

模板< class T>

T * * * * makeData();


};


模板< class T>

T * * * * B :: makeData()

{

* * * *返回A< T> :: create();


}


当我包含时出现编译错误(gcc 3.3.6) Bh在一些X.cpp。

(错误在我所包含的行上,而不是我在哪里tiate)。


但是我没有得到gcc 4.2.2的编译错误。有没有什么方法我可以在gcc3.3.6中避免这个错误?


问候,

~Soumen
I''ve a templatized class member function calling templatized member
function of another class.

//A.h
template <class T>
class A {
public:
static T* * * *create();

};

//B.h
class B {
public:
template<class T>
T* * * * makeData();

};

template<class T>
T* * * *B::makeData()
{
* * * *return A<T>::create();

}

I get a compile error (gcc 3.3.6) when I include B.h in some X.cpp.
(Error is on the line where I include, not where I instantiate).

But I don''t get compile error with gcc 4.2.2. Is there any way that I
can avoid this error in gcc3.3.6?

Regards,
~ Soumen



小修正A不是模板化的类,而是创建是

模板化的方法。


A类{

public:

template< class T>

static T * create();

};


另外,B :: makeData()如下:


// Bh

class B {

public:

template< class T>

T * makeData();


};


模板< class T>

T * B :: makeData()

{

返回A :: create< T>();

}

Little correction A is not templatized class, rather create is
templatized method.

class A {
public:
template <class T>
static T* create();
};

Also, B::makeData() is like following:

//B.h
class B {
public:
template<class T>
T* makeData();

};

template<class T>
T* B::makeData()
{
return A::create<T>();
}


Soumen写道:
Soumen wrote:

[...]

我在某些X.cpp中包含Bh时出现编译错误(gcc 3.3.6)。

(错误已开启)我包含的行,而不是我实例化的地方)。
[...]
I get a compile error (gcc 3.3.6) when I include B.h in some X.cpp.
(Error is on the line where I include, not where I instantiate).



所以它必须怀疑你在那里做错了什么。

So it must suspect you''ve done something wrong there.


但我不喜欢使用gcc 4.2.2获得编译错误。有什么方法我可以在gcc3.3.6中避免这个错误吗?
But I don''t get compile error with gcc 4.2.2. Is there any way that I
can avoid this error in gcc3.3.6?



发布重现错误的确切代码,告诉我们

确切的错误信息,我们可以开始推测

编译器的推理以及它是对还是错。

不要具体,答案可能不会得到更多

特定于我的上面。

Post the exact code that reproduces the error, tell us the
exact error message, and we can begin to speculate about the
compiler''s reasoning and whether it''s right or wrong.
Don''t be as specific, and the answers probably won''t get more
specific than mine from above.


~Soumen
~ Soumen



Schobi

Schobi


Hendrik Schober写道:
Hendrik Schober wrote:

Soumen写道:
Soumen wrote:

> [...]
当我在一些X.cpp中包含Bh时,我得到了一个编译错误(gcc 3.3.6)。
(错误在我包含的行上,而不是我实例化的地方)。
>[...]
I get a compile error (gcc 3.3.6) when I include B.h in some X.cpp.
(Error is on the line where I include, not where I instantiate).



所以它必须怀疑你在那里做错了什么。


So it must suspect you''ve done something wrong there.



......或者编译器无法处理代码,因为它是由于错误或误解而导致的错误标准。

没有办法确定。

... or the compiler is incapable of processing the code because it is
malfunctioning due to a bug or to a misinterpretation of the Standard.
There is no way to tell for sure.


>
>

>但是我没有得到gcc 4.2.2的编译错误。有什么方法可以避免gcc3.3.6中的这个错误吗?
>But I don''t get compile error with gcc 4.2.2. Is there any way that I
can avoid this error in gcc3.3.6?



发布重现错误的确切代码,告诉我们

确切的错误信息,我们可以开始推测

编译器的推理以及它是对还是错。

不要具体,答案可能不会得到更多

特定于我的以上。


Post the exact code that reproduces the error, tell us the
exact error message, and we can begin to speculate about the
compiler''s reasoning and whether it''s right or wrong.
Don''t be as specific, and the answers probably won''t get more
specific than mine from above.



版本之间的差异很可能是因为编译器开发人员已经赶上了标准或修复了他们的错误中的一些错误>
产品。在GCC论坛中提出这个问题是明智的[

以及,而不是在这里]。

Most likely the difference between versions is because the compiler
developers have caught up with the Standard or fixed some bugs in their
product. It would be wise to ask this question in the GCC forum [as
well as, not instead of, here].


>
>

>〜Soumen
>~ Soumen



Schobi


Schobi



V

-

请在通过电子邮件回复时删除资金''A'

我没有回复热门回复,请不要问

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


这篇关于模板相关查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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