Error C2683 Is Not A Polymorphic Type
Contents |
here for a quick overview of source type is not polymorphic dynamic_cast the site Help Center Detailed answers to any
Dynamic_cast Example
questions you might have Meta Discuss the workings and policies of this site About dynamic_cast shared_ptr Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow dynamic_cast vs static_cast Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up C++: “… is not a
C++ Rtti
polymorphic type” while using boost::dynamic_pointer_cast up vote 10 down vote favorite 1 Why do I receive the following error for the following code? 1>C:\Libs\boost_1_44\boost/smart_ptr/shared_ptr.hpp(259): error C2683: 'dynamic_cast' : 'my_namespace::A' is not a polymorphic type 1> D:\[location]\[header_filename].h(35) : see declaration of 'my_namespace::A' 1> C:\Libs\boost_1_44\boost/smart_ptr/shared_ptr.hpp(522) : see reference to function template instantiation 'boost::shared_ptr #include "boost/pointer_cast.hpp" #include "boost/shared_ptr.hpp" struct A { public: A(const MyEnum an_enum_, const int an_int_) : an_enum(an_enum_), an_int(an_int_) {} const MyEnum an_enu
resources Windows Server 2012 resources Programs MSDN subscriptions Overview Benefits Administrators Students Microsoft Imagine Microsoft Student Partners ISV Startups TechRewards Events Community Magazine Forums Blogs Channel 9 Documentation APIs and reference Dev centers Retired content c++ virtual destructor Samples We’re sorry. The content you requested has been removed. You’ll be auto c++ polymorphism redirected in 1 second. C/C++ Building Reference C/C++ Build Errors Compiler Errors C2600 Through C2699 Compiler Errors C2600 Through C2699
C++ Cast
Compiler Error C2683 Compiler Error C2683 Compiler Error C2683 Compiler Error C2600 Compiler Error C2601 Compiler Error C2602 Compiler Error C2603 Compiler Error C2605 Compiler Error C2611 Compiler Error C2612 Compiler Error http://stackoverflow.com/questions/5831765/c-is-not-a-polymorphic-type-while-using-boostdynamic-pointer-cast C2613 Compiler Error C2614 Compiler Error C2616 Compiler Error C2617 Compiler Error C2619 Compiler Error C2624 Compiler Error C2626 Compiler Error C2627 Compiler Error C2628 Compiler Error C2630 Compiler Error C2632 Compiler Error C2633 Compiler Error C2634 Compiler Error C2635 Compiler Error C2636 Compiler Error C2637 Compiler Error C2638 Compiler Error C2640 Compiler Error C2645 Compiler Error C2646 Compiler Error C2647 Compiler Error C2648 Compiler Error https://msdn.microsoft.com/en-us/library/4k5yex0s.aspx C2649 Compiler Error C2650 Compiler Error C2651 Compiler Error C2652 Compiler Error C2653 Compiler Error C2654 Compiler Error C2655 Compiler Error C2656 Compiler Error C2657 Compiler Error C2658 Compiler Error C2659 Compiler Error C2660 Compiler Error C2661 Compiler Error C2662 Compiler Error C2663 Compiler Error C2664 Compiler Error C2665 Compiler Error C2666 Compiler Error C2667 Compiler Error C2668 Compiler Error C2669 Compiler Error C2670 Compiler Error C2671 Compiler Error C2673 Compiler Error C2674 Compiler Error C2675 Compiler Error C2676 Compiler Error C2677 Compiler Error C2678 Compiler Error C2679 Compiler Error C2680 Compiler Error C2681 Compiler Error C2682 Compiler Error C2683 Compiler Error C2687 Compiler Error C2688 Compiler Error C2689 Compiler Error C2690 Compiler Error C2691 Compiler Error C2692 Compiler Error C2693 Compiler Error C2694 Compiler Error C2695 Compiler Error C2696 Compiler Error C2698 TOC Collapse the table of content Expand the table of content This documentation is archived and is not being maintained. This documentation is archived and is not being maintained. Compiler Error C2683 Visual Studio 2015 Other Versions Visual Studio 2013 Visual Studio 2012 Visual Studio 2010 Visual Studio 2008 Visual Studio 2005 Visual Studio .NET 2003 'cast' : 'type' is not a polymorphi
int n; }; class b : public a { public: }; and I next do this: a *x = new b(); b *y = dynamic_cast(x); If I compile this, the compiler (msvc++ 2005) says: error C2683: 'dynamic_cast' : 'a' is not a polymorphic type and gnu g++ 3.2.3 says: http://www.thecodingforums.com/threads/dynamic_cast-a-is-not-a-polymorphic-type.286044/ cannot dynamic_cast `x' (of type `class a*') to type `class b*' ( source type is not polymorphic) I don't understand this. Why can't I dynamically cast a pointer of type base class to some derived class? Probably I have to tell the compiler that class a has http://unick-soft.ru/note.php?id=49 some subclasses. Anyone got an idea? Maurice Termeer Maurice Termeer, Oct 5, 2004 #1 Advertisements Sharad Kala Guest "Maurice Termeer" <> wrote in message > I don't understand this. Why can't I dynamically cast a pointer of type > base class to some derived class? is not Probably I have to tell the compiler > that class a has some subclasses. Anyone got an idea? You got to have at least one virtual function in your base class to use dynamic_cast or to make it polymorphic. Sharad Sharad Kala, Oct 5, 2004 #2 Advertisements Ron Natalie Guest "Sharad Kala" <> wrote in message news:... > > You got to have at least one virtual function in your base class to use > dynamic_cast or to make it polymorphic. > You need to have a polymorphic class to use dynamic_cast error c2683 is IN THIS FASHION. The presence of the virtual function in the base class is what makes it "polymorphic" by DEFINITION. Ron Natalie, Oct 5, 2004 #3 John Harrison Guest "Maurice Termeer" <> wrote in message news:cjtve0$kc7$... > Hi, suppose i've got this: > > class a { > public: > int n; Add this virtual ~a() {} and it will work > }; > > class b : public a { > public: > }; > > and I next do this: > > a *x = new b(); > b *y = dynamic_cast(x); > > If I compile this, the compiler (msvc++ 2005) says: > > error C2683: 'dynamic_cast' : 'a' is not a polymorphic type > john John Harrison, Oct 5, 2004 #4 Rolf Magnus Guest Maurice Termeer wrote: > Hi, suppose i've got this: > > class a { > public: > int n; > }; > > class b : public a { > public: > }; > > and I next do this: > > a *x = new b(); > b *y = dynamic_cast(x); > > If I compile this, the compiler (msvc++ 2005) says: > > error C2683: 'dynamic_cast' : 'a' is not a polymorphic type > > and gnu g++ 3.2.3 says: > > cannot dynamic_cast `x' (of type `class a*') to type `class b*' ( > source type is not polymorphic) > > I don't understand this. Why can't I dynamically cast a pointer of type > base class to some derived class? Just as the compiler says: because your base class is not polymorphic, i.e. doesn't use dynamic typing. Therefore, dynamic type casting c
Обработка изображений Разработка игр Vulkan Работа с текстом Mac OS X Объявления dynamic_cast ошибка C2683: is not a polymorphic type Если при использовании dynamic_cast вы ловили ошибку компиляции C2683, то вам необходимо просто добавить к классу виртуальную функцию или деструктор. class Base1{}; class Base2 { virtual ~Base2() {;} }; class A : public Base1{}; class B : public Base2{}; Base1* pBase1 = new Base1(); Base2* pBase2 = new Base2(); A* pA = dynamic_cast(pBase1); // error C2683: 'dynamic_cast' // : 'Base1' is not a polymorphic type B* pB = dynamic_cast(pBase2); // OK Теги: C++ Ошибки © unick-soft.ru | Design by FCT