我偶然发现了使用以下语法的代码。
int main(){
class foo{
public:
int x;
foo(int y){x=y;}
}
* bar = new foo(1);
}
与更常见的相比,使用它有什么目的/后果
int main(){
class foo{
public:
int x;
foo(int y){x=y;}
};
foo * bar = new foo(1);
}
最佳答案
这可能是一个意见问题,但我认为第一种方法是糟糕的编码实践。
- 它不会影响运行时行为。
- 这使得代码更难阅读。
关于c++ - 单行类声明和实例化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51733125/