CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2009
    Posts
    2

    map using a template value

    I've written the following code, i want to use my own hash map and overwrite the find function suitably. my map values are of type packet_entry_t.

    #ifndef SIM_A_CX_SW_PACKET_STORAGE_H
    #define SIM_A_CX_SW_PACKET_STORAGE_H


    #include <map>

    #ifdef LOG_PACKET_TIMES
    #include <iostream>
    #include <fstream>
    #include <cstring>
    #endif // LOG_PACKET_TIMES

    template <class TTileAddress_t>
    class packet_storage {

    private:
    typedef packet_entry_t<TTileAddress_t> pkt_entry_t;


    typedef std::map<unsigned int, pkt_entry_t>::iterator iterator_t;

    map<unsigned int, pkt_entry_t> pkts_map;

    public:
    packet_storage();
    ~packet_storage();

    // problem 1
    typename std::map<unsigned int, pkt_entry_t>::iterator it;

    //problem 2
    std::map<unsigned int, pkt_entry_t>::iterator find(unsigned int a , unsigned int b);
    std::map<unsigned int, pkt_entry_t>::iterator find(unsigned int );

    }; // end class packet_storage
    #endif //end packet_storage_h


    i receive errors in line //problem 1 and //problem 2 as follow.

    //problem 1 erro:::
    type ‘std::map<unsigned int, packet_entry_t<TTileAddress_t>, std::less<unsigned int>, std::allocator<std:air<const unsigned int, packet_entry_t<TTileAddress_t> > > >’ is not derived from type ‘packet_storage<TTileAddress_t>’

    //problem 2 error:::
    error: type ‘std::map<unsigned int, packet_entry_t<TTileAddress_t>, std::less<unsigned int>, std::allocator<std:air<const unsigned int, packet_entry_t<TTileAddress_t> > > >’ is not derived from type ‘packet_storage<TTileAddress_t>’


    CAN ANY BODY TELL ME WHY? AND HOW CAN I SOLVE THE PROBLEM
    I SOULD BE GRATEFUL.
    THANKS
    ATEFE

  2. #2
    Join Date
    Jul 2002
    Location
    Portsmouth. United Kingdom
    Posts
    2,727

    Re: map using a template value

    This compiles, after supplying my own packet_entry_t structure.

    Code:
    template<class TTileAddress_t>
    class packet_storage
    {
    private:
        typedef packet_entry_t<TTileAddress_t>                pkt_entry_t;
    
        typedef typename std::map<unsigned int, pkt_entry_t>::iterator iterator_t;
    
        std::map<unsigned int, pkt_entry_t> pkts_map;
    
    public:
        packet_storage();
        ~packet_storage();
    
    // problem 1
        typename std::map<unsigned int, pkt_entry_t>::iterator it;
    
    //problem 2
        typename std::map<unsigned int, pkt_entry_t>::iterator find(unsigned int a,
                                                                    unsigned int b);
        typename std::map<unsigned int, pkt_entry_t>::iterator find(unsigned int);
    }; // end class packet_storage
    It mostly needed more 'typename' keywords.

    BTW I see no hash map!
    "It doesn't matter how beautiful your theory is, it doesn't matter how smart you are. If it doesn't agree with experiment, it's wrong."
    Richard P. Feynman

Tags for this Thread

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured