TheChetan
TheChetan

Reputation: 4596

How do I declare a user defined function in OMNet++?

I have declared a function in the c++ file as stated in the documentation and called it in the .ned file. But it gives the following error.

error:expected constructor, destructor, or type conversion before ‘(’ token Define_Function(dijkstra, 1);

The following is my c++ file.

#include <omnetpp.h>
#include "stdio.h"
#include "Node.h"
#include "cdelaychannel.h"

Define_Function(dijkstra, 1);
double dijkstra(double start = 1){
....
....
}

In my network description file, I've called the function.

package myproject;

@license(LGPL);
dijkstra(1.0);

Why is it giving me the error?

Upvotes: 1

Views: 450

Answers (1)

pys
pys

Reputation: 198

If you want to create a function for using it in NED files, you have to do it as described in OMNeT++ Manual. An example could be the following:

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)");

Upvotes: 3

Related Questions