Vector as function return
-
I am working on a C++ application. In the header file:
typedef vector<CMyInfo\*> CMyInfoBachelor; CMyInfoBachelor\* GetBachelorContained (ULONG MyID);
Now in the Cpp file
CMyInfoBachelor\* CMyCache::GetBachelorContained (ULONG MyID) { // Lots of things done here for (..........) { CMyInfo\* pS = GetMyInfo(RS.Get\_UL("ulid",i)); if (pS) pMyInfo->m\_pUsedInTheseBachelor->push\_back(pS); } return pMyInfo->m\_pUsedInTheseBachelor; }
The loop goes twice and i can see 2 separate values are been added to the Vector. But for some reason it's not getting applied. So if i look at debug window:-
m_pUsedInTheseBachelor->;***First*** has the correct value
m_pUsedInTheseBachelor->;***Last*** doesn't have the correct value, it's bunch of junk.
i.e., the Vector get's populated correctly only on the 1st loop iteration. The 2nd looping doesn't add the correct value to vector. I am new to vector and have no idea how to fix it. Also, how to make sure that it return properly? The code that i tried is as follow: In Header file:
vector<CMyInfo\*> CMyInfoBachelor\* GetBachelorContained (ULONG MyID);
And in Cpp file:
vector<CMyInfo\*> CMyInfoBachelor\* CMyCache::GetBachelorContained (ULONG MyID) { // Lots of things done here for (..........) { CMyInfo\* pS = GetMyInfo(RS.Get\_UL("ulid",i)); if (pS) pMyInfo->m\_pUsedInTheseBachelor->push\_back(pS); } return pMyInfo->m\_pUsedInTheseBachelor; }
But i got a bunch of errors. [edit] Tidied up the formatting for you. [/edit]
-
I am working on a C++ application. In the header file:
typedef vector<CMyInfo\*> CMyInfoBachelor; CMyInfoBachelor\* GetBachelorContained (ULONG MyID);
Now in the Cpp file
CMyInfoBachelor\* CMyCache::GetBachelorContained (ULONG MyID) { // Lots of things done here for (..........) { CMyInfo\* pS = GetMyInfo(RS.Get\_UL("ulid",i)); if (pS) pMyInfo->m\_pUsedInTheseBachelor->push\_back(pS); } return pMyInfo->m\_pUsedInTheseBachelor; }
The loop goes twice and i can see 2 separate values are been added to the Vector. But for some reason it's not getting applied. So if i look at debug window:-
m_pUsedInTheseBachelor->;***First*** has the correct value
m_pUsedInTheseBachelor->;***Last*** doesn't have the correct value, it's bunch of junk.
i.e., the Vector get's populated correctly only on the 1st loop iteration. The 2nd looping doesn't add the correct value to vector. I am new to vector and have no idea how to fix it. Also, how to make sure that it return properly? The code that i tried is as follow: In Header file:
vector<CMyInfo\*> CMyInfoBachelor\* GetBachelorContained (ULONG MyID);
And in Cpp file:
vector<CMyInfo\*> CMyInfoBachelor\* CMyCache::GetBachelorContained (ULONG MyID) { // Lots of things done here for (..........) { CMyInfo\* pS = GetMyInfo(RS.Get\_UL("ulid",i)); if (pS) pMyInfo->m\_pUsedInTheseBachelor->push\_back(pS); } return pMyInfo->m\_pUsedInTheseBachelor; }
But i got a bunch of errors. [edit] Tidied up the formatting for you. [/edit]
Your function definitions are wrong in the second version as you are declaring two different return types. The first version was correct. Also, in the first case you say the second value pushed onto the vector is a load of junk, so you need to look at the code of
GetMyInfo(RS.Get_UL("ulid",i));
to check what it is returning.