Try adding const: T* Find( const Op& op ) const
and probably bool FinderFunction( const ItemInfo * itemInfo ) const
.
C2664: Types in Templated Functions
In the header
struct ItemInfo
{
ItemInfo();
~ItemInfo();
};
struct ItemList
{
tList<ItemInfo> itemInfoList;
tArray<ItemInfo *> somethingElse;
};
class Data
{
ItemList itemList;
const ItemInfo* Ref(const char* modName);
}
Also in the header, there is a class containing a template Find function with a referential argument,- the rest is noise but included for illustration.
class Big
{
...
template <class Op>
T * Find(Op& op) const
{
const _Node* pCur = Head();
bool bFound = false;
while (pCur && !bFound)
{
if (!pCur->Item())
pCur = pCur->Next();
else
{
bFound = op.FinderFunction(pCur->Item());
if (!bFound)
pCur = pCur->Next();
}
}
return (bFound && pCur) ? pCur->Item() : NULL;
}
}
In the cpp there is:
class Finder{
const char * string;
{
public: Finder(const char * str) : string(str) { }
bool FinderFunction(ItemInfo* itemInfo)
{
return _stricmp(itemInfo->name, string) == 0;
}
};
The issue is with the Find function in the next block.
const ItemInfo * Data::Ref(const char * itemName)
{
return itemList.itemInfoList.Find(Finder(itemName));
}
The error in VS2019 is:
: error C2664: 'T *tList<T>::Find<Finder>(Op &) const': cannot convert argument 1 from 'Finder' to 'Op &' 1> with 1> [ 1> T=itemInfo, 1> Op=Finder 1> ] 1> and 1> [ 1> Op=`Finder 1> ]
This code once compiled in earlier revisions of C++, it's easy to see why it won't now, but have no idea how to change it to make the conflicting types compatible.
Thanks
-
Viorel 111.8K Reputation points
2023-02-08T14:57:34.0033333+00:00
2 additional answers
Sort by: Most helpful
-
khawlah Alshubati 10 Reputation points
2023-02-08T13:13:52.79+00:00 The error message is indicating that the argument being passed to the
Find
function is of typeFinder
, but the function is expecting an argument of typeOp &
(a reference to anOp
object).To resolve this issue, you'll need to modify the definition of the
Find
function to accept aFinder
object instead of anOp &
object. This could be done by changing the function's signature fromT *Find(Op &) const
toT *Find(Finder) const
.Additionally, it's also possible that you may need to modify the implementation of the
Find
function to work with aFinder
object instead of anOp &
object. For example, if the implementation was previously using theOp
object to compare elements in a list, you may need to modify the implementation to use theFinder
object instead -
khawlah Alshubati 10 Reputation points
2023-02-08T13:14:44.5033333+00:00 The error message is indicating that the argument being passed to the
Find
function is of typeFinder
, but the function is expecting an argument of typeOp &
(a reference to anOp
object).To resolve this issue, you'll need to modify the definition of the
Find
function to accept aFinder
object instead of anOp &
object. This could be done by changing the function's signature fromT *Find(Op &) const
toT *Find(Finder) const
.Additionally, it's also possible that you may need to modify the implementation of the
Find
function to work with aFinder
object instead of anOp &
object. For example, if the implementation was previously using theOp
object to compare elements in a list, you may need to modify the implementation to use theFinder
object instead