Results 1 to 5 of 5

Thread: Dictionary with user defined values

  1. #1
    ngambek2003 is offline Registered User
    Name: Budyanto Himawan
    Organization: WMS Inc.
    Project: Casino back end services
    Join Date
    Sep 2009
    Posts
    87

    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.

    Thanks

  2. #2
    bernard's Avatar
    bernard is offline ZeroC Staff
    Name: Bernard Normier
    Organization: ZeroC, Inc.
    Project: Ice
    Join Date
    Feb 2003
    Location
    Palm Beach Gardens, FL
    Posts
    1,294
    Hi Budyanto,

    I just tried to reproduce this compilation error, unfortunately without success. I updated the minimal C++ demo with:

    Code:
    class A
    {
       int x;
    };
    
    class B extends A
    { 
       int y;
    };
    
    dictionary<int, A> AMap;
    in Hello.ice

    and
    Code:
    class Test
    {
    public:
    
       void AddToMap(const APtr& pA)
       {
    	   _map[pA->x] = pA;
       }
    
    private:
    	AMap _map;
    };
    in Client.cpp

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

    Can you provide a complete test-case?

    Thanks,
    Bernard
    Bernard Normier
    ZeroC, Inc.

  3. #3
    ngambek2003 is offline Registered User
    Name: Budyanto Himawan
    Organization: WMS Inc.
    Project: Casino back end services
    Join Date
    Sep 2009
    Posts
    87
    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.

  4. #4
    ngambek2003 is offline Registered User
    Name: Budyanto Himawan
    Organization: WMS Inc.
    Project: Casino back end services
    Join Date
    Sep 2009
    Posts
    87
    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.

    Thanks.

  5. #5
    marc's Avatar
    marc is offline ZeroC Staff
    Name: Marc Laukien
    Organization: ZeroC, Inc.
    Project: The Internet Communications Engine
    Join Date
    Feb 2003
    Location
    Florida
    Posts
    1,860
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Question on default values in parameters
    By grembo in forum Help Center
    Replies: 2
    Last Post: 06-06-2011, 06:07 AM
  2. Problem with user-defined exception
    By gregors in forum Help Center
    Replies: 1
    Last Post: 03-19-2009, 06:26 AM
  3. Replies: 4
    Last Post: 06-15-2007, 03:47 AM
  4. Slashes in property values kills icegridadmin
    By ctennis in forum Bug Reports
    Replies: 8
    Last Post: 04-19-2007, 10:43 AM
  5. Problems with user-defined types
    By davidcr1983 in forum Help Center
    Replies: 3
    Last Post: 07-14-2006, 02:12 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •