PDA

View Full Version : Map as return Type



Kapil
25th May 2006, 06:52
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 :


map<int, vector<int> > getSB1Info(); // 89 Line - Error
map<int, vector<int> > getSB2Info(); // 90 Line - Error
map<int, vector<int> > getSB3Info(); // 91 Line - Error

inline map<int, vector<int> > CSwitchBlockSoln::getSB1Info() // 112 Line - Error
{
SSBConnectivity sbConn;
int fromTrack;
vector<int> toTrackList;
map< int, vector<int> > sb1Map;
vector<SSBConnectivity> eastSideList = m_pSB1Info->getEastSideList();
int eastSideListSize = eastSideList.size();

for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
{
sbConn = eastSideList[fromTrackIndex];
fromTrack = sbConn.getFromTrack();

sb1Map[fromTrack] = sbConn.getToTrackList();
}

return sb1Map;
}

inline map<int, vector<int> > CSwitchBlockSoln::getSB2Info() //132 Line - Error
{
SSBConnectivity sbConn;
int fromTrack;
vector<int> toTrackList;
map< int, vector<int> > sb2Map;
vector<SSBConnectivity> eastSideList = m_pSB3Info->getEastSideList();
int eastSideListSize = eastSideList.size();

for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
{
sbConn = eastSideList[fromTrackIndex];
fromTrack = sbConn.getFromTrack();
sb2Map[fromTrack] = sbConn.getToTrackList();
}

return sb2Map;
}

inline map<int, vector<int> > CSwitchBlockSoln::getSB3Info() //152 Line - Error
{
SSBConnectivity sbConn;
int fromTrack;
vector<int> toTrackList;
map< int, vector<int> > sb3Map;
vector<SSBConnectivity> eastSideList = m_pSB3Info->getEastSideList();
int eastSideListSize = eastSideList.size();

for(int fromTrackIndex = 0; fromTrackIndex < eastSideListSize; fromTrackIndex++)
{
sbConn = eastSideList[fromTrackIndex];
fromTrack = sbConn.getFromTrack();
sb3Map[fromTrack] = sbConn.getToTrackList();
}

return sb3Map;
}



And here are the errors:



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


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

with regards,
Kapil

ball
25th May 2006, 07:07
What about using pass by reference method instead of direct return it?

Kapil
25th May 2006, 08:12
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

mcosta
25th May 2006, 09:21
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 :


map<int, vector<int> > getSB1Info(); // 89 Line - Error
map<int, vector<int> > getSB2Info(); // 90 Line - Error
map<int, vector<int> > getSB3Info(); // 91 Line - Error



And here are the errors:



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


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



using namespace std;


in the code?

Another way is to declare



std::map< int, std::vector<int> >

Kapil
25th May 2006, 09:44
using namespace std;



yeaps, i have included it at the top after the header files inclusion.





std::map< int, std::vector<int> >


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

mcosta
25th May 2006, 14:03
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?

wysota
25th May 2006, 14:25
Change every occurence of "map" to std::map and everything will be fine. And of course remember to #include <map>

Michiel
25th May 2006, 17:20
If he already has 'using namespace std' there's no need for that. It would help if we could see the whole file.

michael
25th May 2006, 21:49
What compiler is giving you the error on what system? Just curious.

Probably will not help, but worth a try IMHO.

Instead of doing


std::map<some_type, std::vector<some_type>> someFunction1();
std::map<some_type, std::vector<some_type>> someFunction2();
std::map<some_type, std::vector<some_type>> someFunction3();

Try this:


typedef std::map<some_type, std::vector<some_type>> MyMapType;

MyMapType someFunction1();
MyMapType someFunction2();
MyMapType someFunction3();


Might work, might not..

Michael