I want to pass class pointer and a functor as a class template argument. I also dont want that that class pointer to be a local member of functor. I want to use an existing template class which is used elsewhere in the code, so I want to apply a default value to these two parameters so I dont have to change the existing code.
My intention is explained in this class.
class MyClass
{
int local;
/*Dont have member pointer in my current template*/
AnotherClass* anClass;
MyClass(AnotherClass* ptr)
{
/*dont want to create a brand new pointer in my template
the local pointer must be assigned a reference to a pre-existing pointer
passed as argument*/
anClass = ptr;
}
void DoSomething(int val )
{
local = InvokeLogic(val);
/*Dont have this function call DoSomeMore() in my template.
So I want another DoSomeMore() template argument which
is a function-object/functor */
anClass->DoSomeMore(local);
}
}
However, in reality, I have this template thats currently missing some of the information that I want.
template <typename T>
class MyClass
{
T local;
/* AnotherClass* anClass; does not exist */
void DoSomething(T t)
{
local = InvokeLogic(t);
/* want to call this anClass->DoSomeMore(local);
but dont know how to call it. The DoSomething() function object can accept AnotherClass* anClass as a function argument.
*/
}
};
AnotherClass* anClass exists when the instance of MyClass is created.