Archived

This forum has been archived. Please start a new discussion on GitHub.

`communicator' was not declared in this scope?

I want to write a function to do the initialization stuff, like the following code, but the compiler told me that `communicator' was not declared in this scope, after checking the example code, I can't find any point, can somebody tell me why this happened and how to resolve this, thanks.
void Iabs::open(int argc, char* argv[])
{
    Ice::CommunicatorPtr ic;

    ic = Ice::initialize(argc, argv);
    Ice::ObjectPrx base = ic->stringToProxy("callback:tcp -h 192.168.3.98 -p 10000");
    _sProxy = CallbackSenderPrx::checkedCast(base);
    if(!_sProxy)
        throw "Invalid _sProxy";

    Ice::ObjectAdapterPtr adapter = [COLOR="Red"]communicator()[/COLOR]->createObjectAdapterWithEndpoints("Callback.Client", "tcp");
    CallbackReceiverPtr cr = new CallbackReceiverI;
    adapter->add(cr, [COLOR="Red"]communicator()[/COLOR]->stringToIdentity("callbackReceiver"));
    adapter->activate();

    _rProxy = CallbackReceiverPrx::uncheckedCast(adapter->createProxy(communicator()->stringToIdentity("callbackReceiver")));
    if(!_rProxy)
        throw "Invalid _rProxy";

}

Comments

  • benoit
    benoit Rennes, France
    Hi,

    You should use "ic" instead of "communicator()" since you're not using Ice::Application (where the communicator() function is declared) and the communicator you have created is assigned to the "Ice::CommunicatorPtr ic" local variable.

    The examples from the Ice distribution use the Ice::Application class which is the reason why they use this method instead to obtain the communicator created by the Ice::Application class.

    Cheers,
    Benoit.
  • thank you, I know the reason now