首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >FreeBSD上的c++模板有一个奇怪的编译器错误

FreeBSD上的c++模板有一个奇怪的编译器错误
EN

Stack Overflow用户
提问于 2013-06-25 19:25:29
回答 2查看 77关注 0票数 0
代码语言:javascript
运行
复制
I have the following:

class obj
{

    template<typename T>
    inline int foo(T val) const;
};


template<typename T>
int obj::foo(T val)  const
{
    //Do something for PODs
}

template<>
int obj::foo<std::vector<bool>::reference>(std::vector<bool>::reference val) const
{
    //Do something for a boolean in vector of booleans.
}

template<>
int obj::foo<std::string>(std::string var) const
{
    //Do something for string. 
}

使用FreeBSD的g++进行编译时,编译器会报错:

In function int obj::foo<std::_Bit_reference>(std::_Bit_reference) const': /path/to/file.h:22: multiple definition of int obj::foo<std::_Bit_reference>(std::_Bit_reference) const' /path/to/file.h:22 first defined here

std::string也是如此:

In function int obj::foo<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >(std::basic_string<char, std::char_traits<char>, std::allocator<char> >) const':等。

我不知道问题出在哪里。有人能帮我解决这个问题吗?

EN

Stack Overflow用户

发布于 2013-06-25 19:27:49

去掉int obj::foo(T val) const;末尾的分号

票数 1
EN
查看全部 2 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17296022

复制
相关文章

相似问题

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