IceProxy : passing a method pointer as a variable

flatmaxflatmax Member Matt FlaxOrganization: Sole TraderProject: Comms with embedded devices
I get the following compiler error for the listed code :
error: address of overloaded function with no contextual type information

I have an ICE method :
module NAMESPACE {
  class MyClass {
    void myFunc(MyClass* proxy)
    sequence<string> getStringVector(const string &key);
  }
}
I am trying to pass a pointer to this method as a variable using the proxy :
void MyClassI<BASECLASS>::myFunc(const NAMESPACE::MyClassPrx& proxy, const Ice::Current&) { 
  myOtherFunc((vector<string> (*)(const string&))
                     (&IceProxy::NAMESPACE::MyClass::getStringVector))l
}

Any help appreciated.

thanks
Matt

Comments

  • bernardbernard Jupiter, FLAdministrators, ZeroC Staff Bernard NormierOrganization: ZeroC, Inc.Project: Ice ZeroC Staff
    Hi Matt,

    Welcome to our forums. slice2cpp generates two overloaded functions for each Slice operation (e.g. getStringVector), one with a context parameter (as last parameter), and one without.

    What is the declaration of myOtherFunc?

    Best regards,
    Bernard
  • flatmaxflatmax Member Matt FlaxOrganization: Sole TraderProject: Comms with embedded devices
    I see what you are saying, there are 4 methods which map to the getStringVector ... is this perhaps why the compiler is getting confused ?

    To answer your question :

    myOtherFunc is actually a method of a different class. It is called like so :
    e->myOtherFunc
    where e is a pointer member variable.

    The compiler actually reports the problem when I instantiate the templates :

    template class MyClassI<TemplateClass1>;
    template class MyClassI<TemplateClass2>;

    line #1 : instantiated from here
    line #1b error: address of overloaded function with no contextual type information

    line #2 : instantiated from here
    line #2b error: address of overloaded function with no contextual type information

    where line #1 matches the template and #1b matches the myOtherFunc call.
  • flatmaxflatmax Member Matt FlaxOrganization: Sole TraderProject: Comms with embedded devices
    I have managed to get around this problem temporarily (although am currently dubious that it will work as I am not able to get proxy->getStringVector) by using the following :
    NAMESPACE::stringVectorT (IceProxy::NAMESPACE::MyClass::*f)(const string &)=(&IceProxy::NAMESPACE::MyClass::getStringVector);

    Then I use 'f' in my method :
    myOtherFunc(f);

    I now have the problem where the compiler wants the original method to be called with an Ice::Current variable :
    void MyClassI<BASECLASS>::myFunc(const NAMESPACE::MyClassPrx& proxy, const Ice::Current&);

    Where do I get Ice::Current from ?
    The compiler will not let me call myFunc(proxy);
    It is asking me to provide 'Ice::Current'

    thanks
    Matt
  • marcmarc FloridaAdministrators, ZeroC Staff Marc LaukienOrganization: ZeroC, Inc.Project: The Internet Communications Engine ZeroC Staff
    Ice::Current is passed as the last parameter to every operation on the server side. Have a look at the documentation for details.
  • flatmaxflatmax Member Matt FlaxOrganization: Sole TraderProject: Comms with embedded devices
    Sure - I have given up on using proxy method passing for execution in other methods.
  • xdmxdm La Coruña, SpainAdministrators, ZeroC Staff Jose Gutierrez de la ConchaOrganization: ZeroC, Inc.Project: Ice Developer ZeroC Staff
    Hi,

    Based in Ice Hello demo something like this should work.
    // C++ code
    
    void (IceProxy::Demo::Hello::*ptSayHello)(int) = 0;
    
    void doit(HelloPrx instane, void (IceProxy::Demo::Hello::*ptSayHello)(int))
    {
        (instane.get()->*ptSayHello)(0);
    }
    
    // ....
    
    int
    HelloClient::run(int argc, char* argv[])
    {
        //...
        HelloPrx twoway = HelloPrx::checkedCast(
    communicator()->propertyToProxy("Hello.Proxy")->ice_twoway()->ice_timeout(-1)->ice_secure(false));
    
        ptSayHello = &IceProxy::Demo::Hello::sayHello;
        doit(twoway, ptSayHello);
    
  • flatmaxflatmax Member Matt FlaxOrganization: Sole TraderProject: Comms with embedded devices
    Thanks for the demo.
    I think my problem was that the instance was templated and the compiler couldn't map to the method to call ... because of template confusion ... I tried many methods including double casts to override the problem... but to no avail !

    Matt
Sign In or Register to comment.