`
aigo
  • 浏览: 2721435 次
  • 性别: Icon_minigender_1
  • 来自: 宜昌
社区版块
存档分类
最新评论

[C++] error C2955: 'XXXX' : use of class template requires template argumen

C++ 
阅读更多

使用自定义模板类时,编译出现错误:

error C2955: 'XXXX' : use of class template requires template argumen

 

原因:

如果是模板类,则该类的所有函数(不管有没用到模版参数)的实现都必须放在头文件中。

 

例如:

template <class K, class T> 
class KeyedCollection {
public:
    // Create an empty collection
    KeyedCollection();

    // Return the number of objects in the collection
    int size() const;

    void get_vectorone();

    // Insert object of type T with a key of type K into the collection using an “ignore duplicates” policy
    void insert(const K&, const T&);

    // Output data value of objects in the collection, one data value per line
    friend ostream& operator<<(ostream& out, const KeyedCollection<K,T>& e){
        for (int i = 0; i < e.key.size(); i++) { out << e.key.at(i); }
        return out;
    }

private:
    vector<K> key;
    vector<T> object;
};

template <class K, class T> 
KeyedCollection<K,T>::KeyedCollection(){}

template <class K, class T>
int KeyedCollection<K,T>::size() const { return key.size(); }

template <class K, class T> 
void KeyedCollection<K,T>::insert(const K& id, const T& customer){
    key.push_back(id);
    object.push_back(customer);
}

 

 

分享到:
评论

相关推荐

    c++0x, c++11的解决办法 error: #error "Qt requires C++11 support

    error: #error "Qt requires C++11 support c++0x, c++11的解决办法 如果你是用makefile编译还好解决些,但是如果你是用CMake编译,你还得变成CMake的写法. 不过低层原理都一样,都是在g++上作文章. 我来告诉你makefile...

    Keil中C语言与汇编语言混合编程需要注意的几个地方

    sendata.c(81): error C272: 'asm/endasm' requires src-control to be active ``` **解决方法**: 1. 右键单击包含汇编代码的C文件,在弹出的菜单中选择**Options for Group 'XXX'**(XXX为工程名)。 2. 在弹出的...

    emulator: ERROR: x86 emulation currently requires hardware acceleration!

    标题“emulator: ERROR: x86 emulation currently requires hardware acceleration!”是Android开发中常见的一个错误信息,当尝试在没有硬件加速支持的环境中运行Android Emulator时会出现。这个错误提示意味着你...

    c++ 17 ' std::variant ' for c++ 11/14/17

    MPark.VariantC++17 std::variant for C++11/14/17IntroductionMPark.Variant is an implementation of C++17 std::variant for C++11/14/17.Based on Continuously tested against libc++'s std::variant test ...

    Keil_内联汇编的设置问题

    sendata.c(81): error C272: 'asm/endasm' requires src-control to be active sendata.c(87): error C272: 'asm/endasm' requires src-control to be active Target not created ``` 这通常是因为项目设置中未开启...

    Google C++ Style Guide_英文版.pdf

    - **Class Template Argument Deduction:** Use CTAD (Class Template Argument Deduction) to make template class instantiation more concise. - **Designated Initializers:** Use designated initializers for ...

    Unix 编程常见问题解答(中文版)

    - 在 C 编程中,程序员需要手动管理内存分配和释放。 - 常用的内存管理函数包括 `malloc()`, `calloc()`, `realloc()`, `free()` 等。 - 需要注意内存泄漏的问题,即分配的内存没有被正确释放,导致程序占用...

    LINUX7 安装PG15所需依赖包,libzstd-1.5.2

    yum install -y postgresql15-server --&gt; Finished Dependency Resolution Error: Package: postgresql15-15.0-1PGDG.... Requires: libzstd &gt;= 1.4.0 Error: Package: postgresql15-server-15.0-1PGDG.rhel7.x86_64

    Google C++ Style Guide(Google C++编程规范)高清PDF

    link ▶Use standard order for readability and to avoid hidden dependencies: C library, C++ library, other libraries' .h, your project's .h. All of a project's header files should be listed as ...

    systemd-python-219-78.el7.x86_64.rpm

    官方离线安装包,亲测可用。使用rpm -ivh [rpm完整包名] 进行安装

    perl-Class-MethodMaker

    CentOS解决错误:Requires: perl(Class::MethodMaker)。CnetOS中MySQL集群问题。

    C++中常见错误

    ### C++中常见错误 在C++开发过程中,开发者经常会遇到各种各样的编译或运行时错误。本文将根据提供的示例,详细解释几个常见的C++错误及其解决方案。 #### 1. IntelliSense: #error directive: Please use the /...

    Problem Solving with C++ (7th edition)

    This chapter covers the Standard Template Library (STL), a powerful set of C++ libraries: - **STL Containers**: Explanation of STL containers, such as vectors, lists, and maps. - **STL Algorithms**: ...

    c++ Strings

    Similarly, comparing two strings requires the `strcmp()` function rather than the direct use of relational operators like `==` or ` Consider the following examples in C: ```c #include #include ...

    Exploring C++ 11

    Assuming no familiarity with C++, or any other C-based language, you’ll be taught everything you need to know in a logical progression of small lessons that you can work through as quickly or as ...

    yolov5-3.1版本训练时可能会报错及修改方法汇总

    一、 RuntimeError: a view of a leaf Variable that requires grad is being used in an in-place operation 在 yolov5-3.1 版本训练时,可能会出现上述报错。这是因为 PyTorch 中的叶变量(leaf Variable)要求 ...

    cairo-gobject-1.15.12-3.el7.x86_64.rpm

    离线安装包,亲测可用

    catkin_make编译baxter功能包报错处理(csdn)————程序.pdf

    错误信息提示:“This file requires compiler and library support for the ISO C++ 2011 standard”,这表明编译器没有启用C++11的特性支持。C++11是C++的一个重要版本,引入了许多新特性和改进,例如`nullptr`、`...

    gcc-c++-4.4.5-6.el6.x86_64.rpm

    gcc-c++-4.4.5-6.el6.x86_64.rpm

    systemd-python-219-67.el7_7.1.0.1.x86_64.rpm

    官方离线安装包,亲测可用

Global site tag (gtag.js) - Google Analytics