struct node{ int to, w; node(int tt, int ww){to = tt, w = ww;} };讲解一下
时间: 2024-06-07 11:05:39 浏览: 6
这是一个结构体 `node`,它含有两个成员变量 `to` 和 `w`,分别表示该节点指向的另一个节点的编号和边的权值。
在结构体内定义了一个构造函数 `node(int tt, int ww)`,它可以在定义结构体变量时传入两个参数来初始化 `to` 和 `w` 成员变量。
这个结构体通常用于图的存储中,表示图中的一条边或连接两个节点的信息。在使用时可以定义一个数组,每个元素表示一个节点,用链表或 vector 存储以该节点为起点的边的信息,即可表示一个图。
相关问题
no conversion from 'int' to 'struct node *'
This error occurs when you try to assign an integer value to a pointer variable of type 'struct node *'. The compiler is unable to convert an integer to a pointer type.
To resolve this error, make sure you are assigning a pointer value to the pointer variable. Check that the variable you're using is declared as a pointer type and that it points to a valid memory location. Also, check that the value you're assigning is of the correct pointer type.
Here's an example of how to properly assign a pointer value to a pointer variable:
```
struct node *ptr;
struct node n;
ptr = &n; // assigning the address of 'n' to 'ptr'
```
In this example, 'ptr' is declared as a pointer to a 'struct node' type. We create a new 'struct node' object called 'n' and assign its address to 'ptr'. This is a valid pointer assignment because both variables are of the same pointer type.
struct Edge{ int to; int w; Edge(int tt,int ww) : to(tt) , w(ww) { } };详细讲解一下
这是一个结构体定义,名为 Edge。它有两个成员变量,分别为 to 和 w,都是 int 类型。另外还定义了一个构造函数,接受两个 int 类型的参数 tt 和 ww,用来初始化成员变量 to 和 w。
这个结构体看起来是用来表示图的边的,其中 to 表示边的终点,w 表示边的权值。构造函数用来方便地创建 Edge 对象,传入终点和权值即可。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)