0
Follow
0
View

This structure is not very clear ah, ask for a solution

yao2306 注册会员
2023-02-26 15:07

c++ structure, which is defined and used similarly to c++ classes

struct node{
    node (){}  // 结构体的无参构造方法
    node(string ss, int tt){s = ss,t =tt;} // 结构体的有参数构造方法
    string s; // 结构体的字符串型成员变量
    int t; // 结构体的整形成员变量
};
  • When used, we can initialize the struct variable
just as we would initialize a C++ class.
struct node myNode("name", 10); // 定义node结构体 myNode,并初始化它的成员信息
djhaiyang 注册会员
2023-02-26 15:07

The following answers are quoted from GPT-3 model, please use them wisely:

示例:

结构体node定义了一个结构体变量,结构体中由两个成员变量,一个是string型的s,另一个是整型的t。
结构体node有一个构造函数,用于初始化这个结构体。它有两个参数:string ss,和int tt,将ss的值赋给s,将tt的值赋给t。
以下是示例代码:
#include
#include
using namespace std;

struct node{
    node (){}
    node(string ss, int tt){s = ss,t =tt;}
    string s;
    int t;
};

int main(){
    node n("hello",5);  // 调用构造函数,初始化结构体
    cout<< n.s <<' '<< n.t <// 输出: hello 5
    return 0;
}

Please accept my answer if it answers your question

About the Author

Question Info

Publish Time
2023-02-26 15:07
Update Time
2023-02-26 15:07

Related Question

列表list01=[1,2,3],则分别执行命令del list01[1]和list01.remove(1)后的list01为

Visual Studio

multisim电路仿真三角波幅度很小

CIS临床信息系统供应商

Visual Studio 2022已经安时装完之后如何再回到这一步?

我怎样才能得到一个时钟插件工作在我的不和机器人与Discordeno库?

AttributeError: 'list' object has no attribute 'rest'的提问

2022visual studio

arcgis镶嵌至新栅格选择输出位置显示未找到对象

iis网站名称如何修改