问题....嗯,链接器也许 [英] Problems with ....hmm, linker perhaps

查看:52
本文介绍了问题....嗯,链接器也许的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,


IMO下面的程序是合法的,应该编译。


// *****代码启动* ********

// A类的定义

模板< typename T> struct A

{

typedef T value_type;

};


//类的定义B

模板< typename> struct B {};


//函数foo

// importantntype重要!

模板< typename T>

B< typename T :: value_type> foo()

{

返回B< typename T :: value_type>();

};


int main()

{

typedef B< int>(* ptr)(); //函数指针


ptr foo_ptr = foo< A< INT>取代; //函数指针的初始化


返回0;

}

// *****代码结束*** ******


它用g ++和MSVC7.1构建得很好,但后者无法链接:


未解析的外部符号struct B< int> __cdecl foo< struct A< int> >(void)"

(?? $ foo @U?$ A @ H @@@@ YA?AU?$ B @ H @@ XZ)在函数_main


我真的不明白。现在变得越来越怪异了。如果我改变
$ b / b
ptr foo_ptr = foo< A< INT> > ;;


to


ptr foo_ptr;

foo_ptr = foo< A< INT> > ;;


它编译和链接也很好用MSVC 7.1。


在我责怪任何人之前,我想问我是否忽略了什么? IMO代码

没问题。


问候,

Patrick

Dear all,

IMO the following program is legal and should compile.

//***** code start *********
// Definition of class A
template <typename T> struct A
{
typedef T value_type;
};

// Definition of class B
template <typename> struct B {};

// Function foo
// returntype important !
template <typename T>
B<typename T::value_type> foo()
{
return B<typename T::value_type>();
};

int main()
{
typedef B< int >( * ptr )(); // Function pointer

ptr foo_ptr = foo< A<int> >; // Initialization of function pointer

return 0;
}
//***** code end *********

It builds fine with g++ and MSVC7.1, but the latter one fails linking:

unresolved external symbol "struct B<int> __cdecl foo<struct A<int> >(void)"
(??$foo@U?$A@H@@@@YA?AU?$B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick

推荐答案

foo @U?


A @ H @@@@ YA?AU?
A@H@@@@YA?AU?


B @ H @@ XZ)在函数_main


中引用我不太懂的东西。现在变得越来越怪异了。如果我改变
$ b / b
ptr foo_ptr = foo< A< INT> > ;;


to


ptr foo_ptr;

foo_ptr = foo< A< INT> > ;;


它编译和链接也很好用MSVC 7.1。


在我责怪任何人之前,我想问我是否忽略了什么? IMO代码

没问题。


问候,

Patrick

B@H@@XZ) referenced in function _main

what I do not really understand. It is getting a lit more weird now. If I
change

ptr foo_ptr = foo< A<int> >;

to

ptr foo_ptr ;
foo_ptr = foo< A<int> >;

it compiles and links fine as well with MSVC 7.1.

Before I blame anyone, I want to ask if I overlooked something? IMO the code
is fine.

Regards,
Patrick


这篇关于问题....嗯,链接器也许的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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