相关疑难解决方法(0)

具有多个模板参数的C++单模板特化

喂!

我想只专注于两种模板类型中的一种.例如,template <typename A, typename B> class X对于单个函数应该有一个特殊的实现X<float, sometype>::someFunc().

示例代码:

main.h:

#include <iostream>

template <typename F, typename I>
class B
{
public:
    void someFunc()
    {
        std::cout << "normal" << std::endl;
    };

    void someFuncNotSpecial()
    {
        std::cout << "normal" << std::endl;
    };
};

template <typename I>
void B<float, I>::someFunc();
Run Code Online (Sandbox Code Playgroud)

main.cpp中:

#include <iostream>
#include "main.h"

using namespace std;

template <typename I>
void B<float, I>::someFunc()
{
    cout << "special" << endl;
}

int main(int argc, char *argv[])
{
    B<int, int> …
Run Code Online (Sandbox Code Playgroud)

c++ templates specialization

9
推荐指数
2
解决办法
2万
查看次数

标签 统计

c++ ×1

specialization ×1

templates ×1