Base Class Contains Public Function Bar(). foo() is a generic function which takes one parameter When I pass Object of derived class it works fine but when I pass built in data type it must throw exception but it is showing compile time error C2228 In Visual Studio.
class Base
{
public:
void Bar();
};
class Derived:Base
{};
template<typename T>
void foo(T object)
{
if(std::is_base_of<Base,T>::value == true)
object.Bar();//Control does not reaches the point
else
throw "Invalid Parameter";
}
int main()
{
Derived objDerived;
foo(objDerived); //WORKS GOOD
foo(2);//ERROR C2228
}
Aucun commentaire:
Enregistrer un commentaire