Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1096
  • Last Modified:

return a CStringList

My program is as follows:
CStringList CMyClass::Func() const
{
      CStringList aStringList;
                  CString aString = "Hello";
                  aStringList.AddTail(aString);
                  return aStringList;
}

But the following error occured:
error C2664: 'CStringList::CStringList' : cannot convert parameter 1 from 'class CStringList' to 'int'

why? Can I return a CStringList? Thank you very much!
0
syyung6
Asked:
syyung6
1 Solution
 
Tommy HuiCommented:
No, the CStringList does not have a copy constructor so you can not return a copy from the function. You need to pass in a reference to the list you want to manipulate to the function:

void CMyClass::Func(CStringList& aStringList) const
{
  aStringList.AddTail("Hello");
}


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now