模板中类型的非法使用 [英] Illegal use of type in template

查看:115
本文介绍了模板中类型的非法使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是模板的新手.我不知道我在做什么错:

I'm new to templates. I can't figure out what am i doing wrong:

#include "stdafx.h"
#include <iostream>
using namespace std;

template <typename T>
void inc(T* data)
{
    (*T)++;
}

int main()
{
    char x = 'x';
    int b = 1602;

    inc<char>(&x);
    inc<int>(&b);
    cout << x << ", " << b << endl;

    int a = 0;
    cin >> a;
    return 0;
}

在VS2013中编译后,出现错误: 错误1错误C2275:"T":非法使用此类型作为表达式

After compiling in VS2013 i got an error: Error 1 error C2275: 'T' : illegal use of this type as an expression

推荐答案

也许您应该:

template <typename T>
void inc(T* data)
{
    (*data)++;
}

这篇关于模板中类型的非法使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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