带有 () 的 C 对象 - 它有什么作用
C object with () - what does it do?
这段特定的代码是做什么的?更准确地说,什么是测试 tob((;做?
class test {
private:
int a;
int b;
public:
test (int);
test();
};
test::test() {
cout<<"default";
}
test::test (int x=0) {
cout<<"default x=0";
}
int main() {
test tob();
}
我不知道测试 tob((; 做什么,但它没有给出任何编译错误。
test tob();
这声明了一个返回类型为 test
的函数。它不会创建对象。它也被称为最令人烦恼的解析。
要创建test
对象:
test tob;
此外,使用默认参数定义函数(包含构造器(的方式不正确。
test::test (int x=0) { // incorrect. You should put it in function when it's first declared
cout<<"default x=0";
}
下面的代码应该可以工作:
class test {
int a;
int b;
public:
explicit test (int = 0); // default value goes here
};
test::test (int x) {
cout<<"default x=0";
}
int main() {
test tob; // define tob object
}
相关文章:
- archive_read_support_filter_all() 有什么作用?
- 当我们为(;;) 写作时,它做了什么?for 循环中的双分号有什么作用?
- 这个递归函数有什么作用?运行时的复杂性是多少?
- DrawShadow 中的 Elevation 究竟有什么作用?
- 测试"stream >> char"有什么作用?
- "uFlags &= ~CHN_PANNING"命令有什么作用?
- GCC 的 -Wpsabi 选项究竟有什么作用?压制它意味着什么?
- int** a = new int*[n]();这个函数有什么作用?
- C++ 此函数调用之前的(void)有什么作用?
- i+=(i&-i) 有什么作用?它是便携式的吗?
- 这个size_t在 lambda 中有什么作用?C++代码
- 数组下标运算符 ([ ]) 对数组有什么作用?
- 结构之外的节点 * head 有什么作用?
- 重载括号运算符有什么作用?
- clang的"-Ofast"选项在实践中有什么作用,特别是对于与gcc的任何差异?
- std::make_unique_for_overwrite() 对 std::make_unique() 有什么作用?
- 运算符 delete[] 有什么作用?
- 下面的代码有什么作用?c++
- 这个陈述'p = I.ptr<uchar>(i);有什么作用?
- 这个嵌套的名称空间定义有什么作用