import stdstdio;struct Edge int uvw; bool operatorconst Edge aconst return this-waw; e;在D语言编译器运行会报错吗
在D语言编译器中,使用上述代码会报错。
首先,D语言中的结构体(struct)需要使用关键字struct来定义,而不是struct。
其次,在D语言中,需要使用import std.stdio;来导入标准输入输出模块,而不是import stdio;。
最后,D语言中的比较运算符重载需要使用关键字in,而不是const。
修正后的代码如下:
import std.stdio;
struct Edge{
int u,v,w;
bool opCmp(const Edge a)in{
return this.w < a.w;
}
}
void main(){
Edge e;
// 其他代码...
}
注意,上述代码仅修正了语法错误,并没有完整的程序逻辑。在使用结构体Edge之前,需要在main函数中初始化该结构体的实例。此外,还需要编写其他代码来实现特定的功能。
原文地址: http://www.cveoy.top/t/topic/icar 著作权归作者所有。请勿转载和采集!