classBaseClass{
// member variable
// member function
};
class FirstClass:public BaseClass {
};
classSecondClass:publicBaseClass{
};
classThirdClass:publicBaseClass{
};
void func()
{
autoptr=std::make_shared<CLASS_NAME>;
}
int main(intargc, char*argv[])
{
func(CLASS_NAME); // either FirstClass, SecondClass, or ThirdClass
}
When a class is defined as above, I would like to make_shared any object in the func function by specifying the type of class as an argument for the func function from the main function. How should I design the func function?
c++
As a template function, should I receive type arguments instead of arguments?
template<class ClassName>
void func(){
autoptr=std::make_shared<ClassName>();
}
int main() {
func<FirstClass>();
}
If you really want to write in parentheses, you can do it by adding macro definitions.
#defineFUNC(CLASS_NAME) func<CLASS_NAME>()
int main() {
FUNC (FirstClass);
}
579 Understanding How to Configure Google API Key
618 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
925 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.