相关疑难解决方法(0)

在C++标识符中使用下划线有哪些规则?

在C++中通常用某种前缀命名成员变量来表示它们是成员变量而不是局部变量或参数.如果你来自MFC背景,你可能会使用m_foo.我myFoo偶尔也见过.

C#(或者可能只是.NET)似乎建议只使用下划线,如_foo.这是否允许C++标准?

c++ standards naming-conventions c++-faq

906
推荐指数
4
解决办法
24万
查看次数

为什么我不能使用浮点值作为模板参数?

当我尝试float用作模板参数时,编译器会为此代码而烦恼,同时int工作正常.

是因为我不能float用作模板参数吗?

#include<iostream>
using namespace std;

template <class T, T defaultValue>
class GenericClass
{
private:
    T value;
public:
    GenericClass()
    {
        value = defaultValue;
    }

    T returnVal()
    {
        return value;
    }
}; 


int main()
{
    GenericClass <int, 10> gcInteger;
    GenericClass < float, 4.6f> gcFlaot;

    cout << "\n sum of integer is "<<gcInteger.returnVal();
    cout << "\n sum of float is "<<gcFlaot.returnVal();

    return 0;       
}
Run Code Online (Sandbox Code Playgroud)

错误:

main.cpp: In function `int main()':
main.cpp:25: error: `float' is not a …
Run Code Online (Sandbox Code Playgroud)

c++ generics floating-point templates

107
推荐指数
7
解决办法
5万
查看次数