I have a simple class:
class MyExample : public POA_Example
{
CORBA::String_var field;
public:
char* getField();
void setField(const char* f);
};
char* MyExample::getField()
{
return CORBA::string_dup(this->field.out());
}
void MyExample::setField(const char* f)
{
this->field = CORBA::string_dup(f);
}
And main app:
#include "MyExample.h"
#include <iostream>
using std::cout;
int main()
{
MyExample e;
e.setField("Hello");
cout << e.getField() << "\n";
return 0;
}
I use omniORB and the code I gave above doesn't show anything ... Whats the problem here?
If you are using omniORB, you may have to at least call orb_init()
before string operations will work right. The code you have seems fine otherwise.
(Although you do not have to call string_dup()
in the setField()
function, as the String_var
class will automatically do that when you assign it a const char*
.)
(And you are leaking memory by calling e.getField()
in your cout
. But that shouldn't prevent you from seeing something.)