Mixing C++ and Obj-C (odd compile errors)

  • Hi all,

    I'm trying to include some C++ code in my
    Cocoa/Foundation tool, and I'm getting a lot of
    strange errors when compiling.

    Specifically, a section like this:

      template<class T>
      WORD get_next_id(const std::map<WORD, T>& map_cont)
      {
        std::map<WORD, T>::const_iterator it =
    map_cont.begin();

    is generating quite a few errors.

    (WORD is typedef'd as: typedef  UInt16 WORD;)

    The errors are:

    1. error: expected `;' before 'it'
    2. error: dependent-name
    'std::map<cab_header::WORD,T,std::less<cab_header::WORD>,std::allocator<std::pair<const
    cab_header::WORD, T> > >::const_iterator' is parsed as
    a non-type, but instantiation yields a type
    3. note: say 'typename
    std::map<cab_header::WORD,T,std::less<cab_header::WORD>,std::allocator<std::pair<const
    cab_header::WORD, T> > >::const_iterator' if a type is
    meant

    It's been a really long time since I had to deal with
    pure C++ and I confess these errors are far beyond my
    ability to understand, let alone solve.

    I'm hoping someone here has had to do something very
    similar recently, and can offer me some insight. :)

    Any thoughts or suggestions would be greatly
    appreciated.

    Many thanks,

    B


    ____________________________________________________________________________________
    Got a little couch potato?
    Check out fun summer activities for kids.
    http://search.yahoo.com/search?fr=oni_on_mail&p=summer+activities+for+k
    ids&cs=bz
  • On Sep 16, 2007, at 3:52 AM, Brad Peterson wrote:

    > Hi all,
    >
    > I'm trying to include some C++ code in my
    > Cocoa/Foundation tool, and I'm getting a lot of
    > strange errors when compiling.
    >
    > Specifically, a section like this:

    Likely an issue of not using typename correctly, for example in the
    below.

      template<class T>
      WORD get_next_id(typename const std::map<WORD, T>& map_cont)
      {
        typename std::map<WORD, T>::const_iterator it =
    map_cont.begin();
  • Hi,

    > Likely an issue of not using typename correctly, for
    > example in the
    > below.
    >
    > template<class T>
    > WORD get_next_id(typename const std::map<WORD,
    > T>& map_cont)
    > {
    > typename std::map<WORD, T>::const_iterator it =
    > map_cont.begin();

    It was the second typename (preceding "std::map...")
    that did the trick!

    Thank you so much!

    B


    ____________________________________________________________________________________
    Boardwalk for $500? In 2007? Ha! Play Monopoly Here and Now (it's updated for today's economy) at Yahoo! Games.
    http://get.games.yahoo.com/proddesc?gamekey=monopolyherenow
  • > It's been a really long time since I had to deal with
    > pure C++...

    And

    > It was the second typename...

    Yeah, I went through some of the same issues. The standard changed things
    while I wasn't actively using C++, and GCC is now really compliant. You
    might want to pick up a recent book and review some of this.

    --
    Scott Ribe
    <scott_ribe...>
    http://www.killerbytes.com/
    (303) 722-0567 voice
previous month september 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
Go to today