Results 1 to 9 of 9

Thread: Map as return Type

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Map as return Type

    Hi,

    I am finding a strange problem... I have created a function with return type as map.. On one system it works pretty fine but when i transferred my app to another system for testing it was giving error... I couldnt find the reason for the error...

    Here is the code :
    Qt Code:
    1. map<int, vector<int> > getSB1Info(); // 89 Line - Error
    2. map<int, vector<int> > getSB2Info(); // 90 Line - Error
    3. map<int, vector<int> > getSB3Info(); // 91 Line - Error
    4.  
    5. inline map<int, vector<int> > CSwitchBlockSoln::getSB1Info() // 112 Line - Error
    6. {
    7. SSBConnectivity sbConn;
    8. int fromTrack;
    9. vector<int> toTrackList;
    10. map< int, vector<int> > sb1Map;
    11. vector<SSBConnectivity> eastSideList = m_pSB1Info->getEastSideList();
    12. int eastSideListSize = eastSideList.size();
    13.  
    14. for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
    15. {
    16. sbConn = eastSideList[fromTrackIndex];
    17. fromTrack = sbConn.getFromTrack();
    18.  
    19. sb1Map[fromTrack] = sbConn.getToTrackList();
    20. }
    21.  
    22. return sb1Map;
    23. }
    24.  
    25. inline map<int, vector<int> > CSwitchBlockSoln::getSB2Info() //132 Line - Error
    26. {
    27. SSBConnectivity sbConn;
    28. int fromTrack;
    29. vector<int> toTrackList;
    30. map< int, vector<int> > sb2Map;
    31. vector<SSBConnectivity> eastSideList = m_pSB3Info->getEastSideList();
    32. int eastSideListSize = eastSideList.size();
    33.  
    34. for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
    35. {
    36. sbConn = eastSideList[fromTrackIndex];
    37. fromTrack = sbConn.getFromTrack();
    38. sb2Map[fromTrack] = sbConn.getToTrackList();
    39. }
    40.  
    41. return sb2Map;
    42. }
    43.  
    44. inline map<int, vector<int> > CSwitchBlockSoln::getSB3Info() //152 Line - Error
    45. {
    46. SSBConnectivity sbConn;
    47. int fromTrack;
    48. vector<int> toTrackList;
    49. map< int, vector<int> > sb3Map;
    50. vector<SSBConnectivity> eastSideList = m_pSB3Info->getEastSideList();
    51. int eastSideListSize = eastSideList.size();
    52.  
    53. for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
    54. {
    55. sbConn = eastSideList[fromTrackIndex];
    56. fromTrack = sbConn.getFromTrack();
    57. sb3Map[fromTrack] = sbConn.getToTrackList();
    58. }
    59.  
    60. return sb3Map;
    61. }
    To copy to clipboard, switch view to plain text mode 

    And here are the errors:

    [HTML]
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:89:
    error: ISO C++ forbids declaration of `map' with no type
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:89:
    error: expected `;' before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:90:
    error: ISO C++ forbids declaration of `map' with no type
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:90:
    error: expected `;' before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:91:
    error: ISO C++ forbids declaration of `map' with no type
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:91:
    error: expected `;' before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:112
    : error: expected init-declarator before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:112
    : error: expected `,' or `;' before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:132
    : error: expected init-declarator before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:132
    : error: expected `,' or `;' before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:152
    : error: expected init-declarator before '<' token
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:152
    : error: expected `,' or `;' before '<' token
    [/HTML]

    Please tell me what can i do to fix up this problem...
    Thank you,

    with regards,
    Kapil
    Last edited by Kapil; 25th May 2006 at 05:55.
    All you have to decide is what to do with the time that is given to you

  2. #2
    Join Date
    Jan 2006
    Posts
    75
    Thanks
    3
    Thanked 5 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Map as return Type

    What about using pass by reference method instead of direct return it?

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Map as return Type

    Quote Originally Posted by ball
    What about using pass by reference method instead of direct return it?
    Problem is that it is not able to recognize map as a return type... Passing by reference or by value comes later... On the other hand it recognizes map as a return type on one system and doesnt on the other system...

    Kapil
    All you have to decide is what to do with the time that is given to you

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Map as return Type

    Quote Originally Posted by Kapil
    Hi,

    I am finding a strange problem... I have created a function with return type as map.. On one system it works pretty fine but when i transferred my app to another system for testing it was giving error... I couldnt find the reason for the error...

    Here is the code :
    Qt Code:
    1. map<int, vector<int> > getSB1Info(); // 89 Line - Error
    2. map<int, vector<int> > getSB2Info(); // 90 Line - Error
    3. map<int, vector<int> > getSB3Info(); // 91 Line - Error
    To copy to clipboard, switch view to plain text mode 

    And here are the errors:

    [HTML]
    C:/backup/picoga_gui_view/PICOGA/Router/PiCoGA1.0/INCLUDE/CSwitchBlockSoln.h:89:
    error: ISO C++ forbids declaration of `map' with no type
    [/HTML]

    Please tell me what can i do to fix up this problem...
    Thank you,

    with regards,
    Kapil
    Sorry for the stupid quastion?

    There is the istruction

    Qt Code:
    1. using namespace std;
    To copy to clipboard, switch view to plain text mode 

    in the code?

    Another way is to declare

    Qt Code:
    1. std::map< int, std::vector<int> >
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Map as return Type

    Quote Originally Posted by mcosta
    Qt Code:
    1. using namespace std;
    To copy to clipboard, switch view to plain text mode 
    yeaps, i have included it at the top after the header files inclusion.

    Quote Originally Posted by mcosta
    Qt Code:
    1. std::map< int, std::vector<int> >
    To copy to clipboard, switch view to plain text mode 
    if there is the inclusion of namespace std then there is no need for me to write it this way.. and if yes then why so???

    thanks,

    regards,
    Kapil
    All you have to decide is what to do with the time that is given to you

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Map as return Type

    Quote Originally Posted by Kapil
    if there is the inclusion of namespace std then there is no need for me to write it this way.. and if yes then why so???

    regards,
    Kapil
    Can you post the file?
    A camel can go 14 days without drink,
    I can't!!!

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Map as return Type

    Change every occurence of "map" to std::map and everything will be fine. And of course remember to #include <map>

  8. #8
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Map as return Type

    If he already has 'using namespace std' there's no need for that. It would help if we could see the whole file.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  9. #9
    Join Date
    Jan 2006
    Location
    South Carolina, USA
    Posts
    34
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Map as return Type

    What compiler is giving you the error on what system? Just curious.

    Probably will not help, but worth a try IMHO.

    Instead of doing
    Qt Code:
    1. std::map<some_type, std::vector<some_type>> someFunction1();
    2. std::map<some_type, std::vector<some_type>> someFunction2();
    3. std::map<some_type, std::vector<some_type>> someFunction3();
    To copy to clipboard, switch view to plain text mode 
    Try this:
    Qt Code:
    1. typedef std::map<some_type, std::vector<some_type>> MyMapType;
    2.  
    3. MyMapType someFunction1();
    4. MyMapType someFunction2();
    5. MyMapType someFunction3();
    To copy to clipboard, switch view to plain text mode 

    Might work, might not..

    Michael

Similar Threads

  1. [SOLVED] DirectShow Video Player Inside Qt
    By ToddAtWSU in forum Qt Programming
    Replies: 16
    Last Post: 3rd November 2011, 07:47
  2. Carriage Return in QString
    By incapacitant in forum Newbie
    Replies: 7
    Last Post: 2nd December 2010, 09:18
  3. When is the best time to delete a QCanvasItem
    By irudkin in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2007, 21:28
  4. Type and User Type
    By campana in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2006, 23:22
  5. use libs under qt4
    By raphaelf in forum Qt Programming
    Replies: 6
    Last Post: 27th February 2006, 17:59

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.