如下代码:Node(const int& d):data(d),next(NULL){} 这句是什么意思?
struct Node{ int data; Node *next; Node(const int& d):data(d),next(NULL){} };
如下代码:Node(const int& d):data(d),next(NULL){} 这句是什么意思?
struct Node{ int data; Node *next; Node(const int& d):data(d),next(NULL){} };
#include<stdio.h>
struct Node{
int data;
Node *next;
Node(const int& d):data(d),next(NULL){}
};
int main(){
Node point = Node(4);
printf("%d",point.data); //数据域就是4 指针域就是NULL
return 1;
}
带参数的构造函数吧。在C++类中是有这种写法的,带参数的构造函数,构造一个对象。在结构体里面,功能一样,可以构造一个结构体实例。