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

Dictionary with user defined values

How do I add values to a dictionary?

I have slice classes defined as follows

class A
int a;

class B extends A
int b;

dictionary<int, A> ASeq;

Now in my c++ code I have the following function

void AddToMap(const APtr &pA)
m_mapA[pA->a] = pA

I get a compilation error about a private destructor.



  • bernard
    bernard Jupiter, FL
    Hi Budyanto,

    I just tried to reproduce this compilation error, unfortunately without success. I updated the minimal C++ demo with:
    class A
       int x;
    class B extends A
       int y;
    dictionary<int, A> AMap;


    class Test
       void AddToMap(const APtr& pA)
    	   _map[pA->x] = pA;
    	AMap _map;

    in Client.cpp

    and as expected, it compiled fine (with Visual Studio 2010).

    Can you provide a complete test-case?

  • Hi Bernard,

    Thanks...I just tried it again and it does compile fine now.

    Initiallly I did not pass in APtr into the function. It might have failed then. I was passing in A.

    I thought I tried compiling after changing it to APtr.

    Oh well. Thanks anyway.
  • So actually in the C++ mapping AMap is really map<int, APtr> and not map<int, A>.

    If I use the streaming api to stream the map into bytes that should work right?
    It would know that A in the map is really APtr.

  • Yes, Ice always uses smart pointers for class instances. The streaming API will stream the contents of the class instance, regardless of the language mapping. Have a look at the writeObject method as described here.