dir.by  
  Поиск  
Компьютер, программы
C++
 dynamic_cast in C++ (converting a pointer to a different type and checking validity in runtime) 
посмотрели 1381 раз
обновлено: 18 November 2024
TYPE* dynamic_cast<TYPE*> (object);
If you attempt to cast to pointer to a type that is not a type of actual object, the result of the cast will be NULL
Example
  C++  
#include <string>

class Location
{
     public: virtual ~Location() { }

     public: std::string m_Street;
     public: std::string m_City;
};

class Shop : public Location
{
     public: virtual ~Shop() { }

     public: std::string m_ShopName;
};

int main()
{
     Location* pL = new Shop();

     Shop* pS = dynamic_cast<Shop*> (pL); // converting pointer of Location class to Shop class
     if (pS != NULL)
     {
          pS->m_ShopName = "Booking shop";
     }
}
 
 
Next topic →
std::map<Key, Value> is a set of keys and values in C++. An important feature of std::map is to quickly find a value by key
 
Your feedback ... Comments ...
   
Your Name
Your comment (www links can only be added by a logged-in user)

Экскурсии по Москве Экскурсии по Москве: пешеходные, автобусные и речные прогулки на любой вкус
Анонс! Ярмарка вакансий для молодежи, работа (учащихся, которые хотели бы подработать в свободное время, а также выпускники)|||Минск, Витебск, Гомель, Гродно, Могилев, Борисов, Полоцк, Брест, Барановичи, Пинск с 13 по 17 апреля 2026
  Объявления  
  Объявления  
 
dynamic_cast in C++ (converting a pointer to a different type and checking validity in runtime)
std::map<Key, Value> is a set of keys and values in C++. An important feature of std::map is to quickly find a value by key
Pass a function as a parameter to a function (callback) | C++
OpenGL
Create a new OpenGL application on C++ | Library GLUT, Visual Studio
Creating a OpenGL app with 3D pyramid drawing and a motion camera on C++ | Visual Studio | Library glut for using OpenGL
Create a new OpenGL ES2 app on C++ in Windows | Visual Studio, Desktop application

  Ваши вопросы присылайте по почте: info@dir.by  
Яндекс.Метрика