Answer the question
In order to leave comments, you need to log in
How to explicitly cast a base class to a child?
void SplitString(int choice)
{
char string[100];
system("clear");
LevelHead("Тестирование","Строка-Идентификатор","Сложение строк");
cout << "Введите значение второго операнда" << endl;
cin >> string;
Str_Indef strIndef(string);
strIndef = strIndef + (Str_Indef)pointClass[strArray[choice]];
strIndef.Print();
Pause();
}
Answer the question
In order to leave comments, you need to log in
i need to cast parent class to child class
class A
{
public:
virtual ~A() {}
};
class B : public A
{
};
A *pa = ...;
B *pb1 = dynamic_cast<B*>(pa);
B *pb2 = static_cast<B*>(pa);
B *pb3 = (B *)pa;
B *pb4 = reinterpret_cast<B*>(pa);
I suspect you need this:
#include <iostream>
class Base
{
public:
virtual void foobar(){}
// или:
//virtual void foobar() = 0;
virtual ~Base(){}
};
class Child : public Base
{
public:
virtual ~Child() {}
void foobar() override { std::cout << "foobar" << std::endl; }
};
int main()
{
Base *b = new Child;
b->foobar();
delete b;
return 0;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question