Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. inaccessible typecast

inaccessible typecast

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LionAM
    wrote on last edited by
    #1

    Hello! I have two classes A and B, which is derived of A class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } }; When I try A a; B<int> b; a = b; //Error I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... Alex

    G T 2 Replies Last reply
    0
    • L LionAM

      Hello! I have two classes A and B, which is derived of A class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } }; When I try A a; B<int> b; a = b; //Error I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... Alex

      G Offline
      G Offline
      Gary R Wheeler
      wrote on last edited by
      #2

      You defined a const conversion operator, but your assignment is to a non-const l-value.


      Software Zen: delete this;

      Fold With Us![^]

      1 Reply Last reply
      0
      • L LionAM

        Hello! I have two classes A and B, which is derived of A class A {}; template<class T> class B : protected A { public: operator const A&() { return *this; } }; When I try A a; B<int> b; a = b; //Error I get the Error error C2243: 'type cast' : Konvertierung von 'class B *' zu 'const class A &' existiert bereits, aber es ist kein Zugriff darauf moeglich Why? I have defined an public conversion operator... Alex

        T Offline
        T Offline
        toxcct
        wrote on last edited by
        #3

        LionAM wrote:

        public: operator const A&() { return *this; }

        create two operators, one const, one not :

        template<class T> class B : protected A {
        public:
        operator const A&() const { return *this; }
        operator A&() { return *this; }
        };


        TOXCCT >>> GEII power

        [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

        L 1 Reply Last reply
        0
        • T toxcct

          LionAM wrote:

          public: operator const A&() { return *this; }

          create two operators, one const, one not :

          template<class T> class B : protected A {
          public:
          operator const A&() const { return *this; }
          operator A&() { return *this; }
          };


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          L Offline
          L Offline
          LionAM
          wrote on last edited by
          #4

          Thank you for your answers! Unfortunately this seems not to work under Visual C++ 6 (another bug?) - but it does work in VC2005 Express... But if I declare the classes as friends, it works (and I even don't need the public type cast operator). Alex

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups