Omnet++ 如何在OMNet+;中声明用户定义的函数+;? 我在C++文件中声明了一个函数,如文档中所述,并在.ND文件中调用它。但它给出了以下错误 error:expected constructor, destructor, or type conversion before ‘(’ token Define_Function(dijkstra, 1); 以下是我的C++文件。< /P> #include <omnetpp.h> #include "stdio.h" #include "Node.h" #include "cdelaychannel.h" Define_Function(dijkstra, 1); double dijkstra(double start = 1){ .... .... }

Omnet++ 如何在OMNet+;中声明用户定义的函数+;? 我在C++文件中声明了一个函数,如文档中所述,并在.ND文件中调用它。但它给出了以下错误 error:expected constructor, destructor, or type conversion before ‘(’ token Define_Function(dijkstra, 1); 以下是我的C++文件。< /P> #include <omnetpp.h> #include "stdio.h" #include "Node.h" #include "cdelaychannel.h" Define_Function(dijkstra, 1); double dijkstra(double start = 1){ .... .... },omnet++,Omnet++,为什么会出现错误?如果要在NED文件中创建使用它的函数,必须按照中的说明执行。例如: static cNEDValue ned_foo(cComponent *context, cNEDValue argv[], int argc) int a = (long) argv[0]; int b = (long) argv[1]; return a*b; } Define_NED_Function(ned_foo,"int ned_foo(int a, int b)")

为什么会出现错误?

如果要在NED文件中创建使用它的函数,必须按照中的说明执行。例如:

static cNEDValue ned_foo(cComponent *context, cNEDValue argv[], int argc) 
  int a = (long) argv[0];   
  int b = (long) argv[1];   
  return a*b; 
}

Define_NED_Function(ned_foo,"int ned_foo(int a, int b)");
static cNEDValue ned_foo(cComponent *context, cNEDValue argv[], int argc) 
  int a = (long) argv[0];   
  int b = (long) argv[1];   
  return a*b; 
}

Define_NED_Function(ned_foo,"int ned_foo(int a, int b)");