主页
C++
C++ 构造函数
demo_constructor
运行 ❯
×
更改方向
保存代码
更改主题
#include
using namespace std; class MyClass { // The class public: // Access specifier MyClass() { // Constructor cout << "Hello World!"; } }; int main() { MyClass myObj; // Create an object of MyClass (this will call the constructor) return 0; }
Hello World!