I could’ve sworn this worked some time ago when my object was declared on the heap instead of on the stack. I have a function that takes a pointer to a base class ( detail::DuplicateFn ). – Though as that is a virtual class the actual pointers are given by a derived class (ie dteail::SkipFn)
1>GMProject.cpp(298): error C2664:
'void xml_tree<V>::combine_if<bool(__cdecl *)(const T &,const T &)>(const xml_tree<V> &,Predicate,const detail::DuplicateFn *)' :
cannot convert parameter 3 from 'detail::SkipFn (__cdecl *)(void)' to 'const detail::DuplicateFn *'
My function:
void GMProject::CombineTree(const pTree& Other) {
detail::SkipFn foo();
ProjectTree.combine_if(Other, &SimilarTreeValue<GMProject::pTree>, &foo);
}
Where ProjectTree.combine_if() as third parameter requires a pointer to “DuplicateFn” – and SkipFn is derived from DuplicateFn.
As said this works (like I expect) correctly if I declare “foo” on the heap. However it doesn’t when declaring foo on the stack (or -ultimatelly- making foo a temporary). Why is that?
foois not an object. It’s a function whose return type isdetail::SkipFn. So, instead try –Is there any difference between List x; and List x();?