Both xPtr
and yPtr
are pointers to integer. Yes, compilers ignore the space.
To bind an oTcl
variable (x and y) with C++ variables (*xPtr
and *yPtr
), use the following code.
Tcl& tcl = Tcl::instance();
tcl.eval("set variable_in_tcl");
variable_in_c++ = atoi(tcl.result());
As, I have understand, you are calling the add()
function which will take the variables xPtr
and yPtr
value from oTcl
script and print the value of variable. So, your code will look as follows:
class MyAgent : public Agent
{
private:
// Use x and y in tcl script
int* xPtr;
int *yPtr;
void add();
public:
MyAgent(); // Declaration of constructor
};
MyAgent::MyAgent() : Agent(PT_UDP)
{
Tcl& tcl = Tcl::instance();
tcl.eval("set x");
*xPtr = atoi(tcl.result());
tcl.eval("set y");
*yPtr = atoi(tcl.result());
}
void MyAgent::add()
{
printf("\nx=%d and y = %d\nx+y = %d\n", *xPtr,*yPtr,*xPtr+*yPtr);
printf("xPtr=%d\n",*xPtr);
printf("yPtr=%d\n",*yPtr);
}