Reputation: 4523
Using Visual Studio 2012, the following compiles:
void Stuff()
{
CMap <int, int, int, int > myMap;
}
But when I try to return such a CMap, like this:
CMap<int, int, int, int> GetEncodingMap()
{
CMap <int, int, int, int> encodingMap;
return encodingMap;
}
I get the following compile error:
1> c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afx.h(559) : see declaration of 'CObject::CObject'
1> c:\program files (x86)\microsoft visual studio 11.0\vc\atlmfc\include\afx.h(534) : see declaration of 'CObject'
1> This diagnostic occurred in the compiler generated function 'CMap<KEY,ARG_KEY,VALUE,ARG_VALUE>::CMap(const CMap<KEY,ARG_KEY,VALUE,ARG_VALUE> &)'
1> with
1> [
1> KEY=int,
1> ARG_KEY=int,
1> VALUE=int,
1> ARG_VALUE=int
1> ]
This seems to always be the case, no matter what types I use in the CMap.
Could somebody help me understand what his happening? Is it ever possible to return a CMap from a function?
Upvotes: 0
Views: 500
Reputation: 9707
GetEncodingMap() method doesn't create an object, just declaring and returning. Try creating before returning.
Upvotes: 0
Reputation: 5138
CMap
is a non-copyable object, as it inherits from CObject
which has a private copy constructor. If you want to make it copyable, you will need to inherit from CMap and provide your own, although I'm not sure how viable that is.
Upvotes: 2
Reputation: 16759
This is just a convoluted way of MFC trying to prevent you from copying CMap object. You can't copy a CMap object.
Upvotes: 0