Share via

Trouble compiling a member variable using a CList template with VS Community 2012

Michael Tadyshak 80 Reputation points
2023-09-17T22:39:39.6433333+00:00
//Class ParmContainer has a constructor that takes 3 CString argments with the third argument optional

class ParmContainer
{
public:
	ParmContainer(CString label, CString type, CString format = CString("") );
}

//Here is the constructor
ParmContainer::ParmContainer(CString label, CString type, CString format)
{
	Create(label, type, format);
}

//Class AddParms has a variable m_Parms declared as a template for a CList object passing in the class ParmContainer as the type
class AddParms
{
...
public:
	CList<ParmContainer,ParmContainer&> m_Parms;	
}

//Function Create() calls m_Parms.AddHead(ParmContainer(name, type)); which produces errors
bool AddParms::Create(CString name, CString type)
{
...
	m_Parms.AddHead(ParmContainer(name, type));
	
	return (true);
}

This code compiled OK on .NET 2003.  I am using Visual Studio Community 2022 and .NET 4.8 and all the following errors are produced:

AddParms.cpp(50,9): error C2665: 'CList<ParmContainer,ParmContainer &>::AddHead': no overloaded function could convert all the argument types

\MSVC\14.37.32822\atlmfc\include\afxtempl.h(727,7): message : could be 'void CList<ParmContainer,ParmContainer &>::AddHead(CList<ParmContainer,ParmContainer &> *)'

AddParms.cpp(50,9): message : 'void CList<ParmContainer,ParmContainer &>::AddHead(CList<ParmContainer,ParmContainer &> *)': cannot convert argument 1 from 'ParmContainer' to 'CList<ParmContainer,ParmContainer &> *'

AddParms.cpp(50,31): message : No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

\MSVC\14.37.32822\atlmfc\include\afxtempl.h(723,11): message : or       'POSITION CList<ParmContainer,ParmContainer &>::AddHead(ARG_TYPE)'
1>        with
1>        [
1>            ARG_TYPE=ParmContainer &
1>        ]
AddParms.cpp(50,9): message : 'POSITION CList<ParmContainer,ParmContainer &>::AddHead(ARG_TYPE)': cannot convert argument 1 from 'ParmContainer' to 'ARG_TYPE'
1>        with
1>        [
1>            ARG_TYPE=ParmContainer &
1>        ]

Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


Answer accepted by question author

RLWA32 52,571 Reputation points
2023-09-17T23:58:12.2266667+00:00

Declare your CList like this.

CList<ParmContainer, const ParmContainer&> m_Parms;

Was this answer helpful?

1 person found this answer helpful.
0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.