Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Vector as function return

Vector as function return

Scheduled Pinned Locked Moved C / C++ / MFC
c++graphicsdebugginghelptutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Donguy1976
    wrote on last edited by
    #1

    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]

    L 1 Reply Last reply
    0
    • D Donguy1976

      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]

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups