f*z 发帖数: 421 | 1 大牛,同学们,请教,static member method 可不可用default argument?比如,
enum Index
{
INDEX_A = 0,
INDEX_B
};
class foo
{
public:
static void method1( int a, int b = Index::INDEX_A);
};
编译可以过,但有什么要注意的地方?
多谢! |
m*********a 发帖数: 3299 | 2 你用的是那个版本的IDE,我用的是Code::Blocks
int b=Index::INDEX_A 或int b=Index.INDEX_A无法通过编译
只能用 int b=INDEX_A 或 Index b=INDEX_A;
太落后了。
而且enum 在C++是个class么?INDEX_A 的default value 是0,INDEX_B是1.
【在 f*z 的大作中提到】 : 大牛,同学们,请教,static member method 可不可用default argument?比如, : enum Index : { : INDEX_A = 0, : INDEX_B : }; : class foo : { : public: : static void method1( int a, int b = Index::INDEX_A);
|
p***o 发帖数: 1252 | 3 For C++98, put Index in class foo to avoid polluting the outer namespace.
For C++11, you can use enum class so Index::INDEX_A will compile.
【在 m*********a 的大作中提到】 : 你用的是那个版本的IDE,我用的是Code::Blocks : int b=Index::INDEX_A 或int b=Index.INDEX_A无法通过编译 : 只能用 int b=INDEX_A 或 Index b=INDEX_A; : 太落后了。 : 而且enum 在C++是个class么?INDEX_A 的default value 是0,INDEX_B是1.
|
m*********a 发帖数: 3299 | 4 好了,可以用了。Index::INDEX_A
但是还是没有办法用Index.INDEX_A,这个只能在Visual Studio用吗?
【在 p***o 的大作中提到】 : For C++98, put Index in class foo to avoid polluting the outer namespace. : For C++11, you can use enum class so Index::INDEX_A will compile.
|
s*******8 发帖数: 12734 | 5 index.INDEX_A not C++, it is java or c#
【在 m*********a 的大作中提到】 : 好了,可以用了。Index::INDEX_A : 但是还是没有办法用Index.INDEX_A,这个只能在Visual Studio用吗?
|