首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么连接器在这个模板中抱怨多个定义?

为什么连接器在这个模板中抱怨多个定义?

提问于 2018-03-13 12:14:22
回答 2关注 0查看 180

我的代码如下:

代码语言:javascript
复制
# ifndef MAXIMUM_HPP
# define MAXIMUM_HPP

template<typename T>
T maximum(const T & a, const T & b)
{
    return a > b ? a : b ;
}

/* dumb specialization */
template<>
int maximum(const int & a, const int & b)
{
    return a > b ? a : b ;
}

# endif // MAXIMUM_HPP

以下是链接器消息:

代码语言:javascript
复制
g++ -o test.exe Sources\test.o Sources\other_test.o
Sources\other_test.o:other_test.cpp:(.text+0x0): multiple definition of `int maximum<int>(int const&, int const&)'
Sources\test.o:test.cpp:(.text+0x14): first defined here

回答

和开发者交流更多问题细节吧,去 写回答
相关文章

相似问题

相关问答用户
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档