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. Why C++ doesn't use the parent's class function? (C++ question)

Why C++ doesn't use the parent's class function? (C++ question)

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++help
5 Posts 2 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.
  • G Offline
    G Offline
    Green Fuze
    wrote on last edited by
    #1

    Hey everybody. Here's a C++ question. I have 2 classes:

    template
    class A_template
    {
    public:
    ... other stuff ...

    void operator = (T* other){ _obj = other; }

    protected:
    T* _x;
    };
    //-----------------------------------------------
    class B : public A_template
    {
    ... some functions ...
    };

    Now, the problem is that if I have the following line of code: C* x = CreateC(); B b; b = x; // <--- compiler returns that there is no possible conversion, but it does, in A ! what am I doing wrong?? Thanks a lot !!! :-)

    G 1 Reply Last reply
    0
    • G Green Fuze

      Hey everybody. Here's a C++ question. I have 2 classes:

      template
      class A_template
      {
      public:
      ... other stuff ...

      void operator = (T* other){ _obj = other; }

      protected:
      T* _x;
      };
      //-----------------------------------------------
      class B : public A_template
      {
      ... some functions ...
      };

      Now, the problem is that if I have the following line of code: C* x = CreateC(); B b; b = x; // <--- compiler returns that there is no possible conversion, but it does, in A ! what am I doing wrong?? Thanks a lot !!! :-)

      G Offline
      G Offline
      Green Fuze
      wrote on last edited by
      #2

      Oh, and the definition of B is: class B : public A_template. :-)

      E 1 Reply Last reply
      0
      • G Green Fuze

        Oh, and the definition of B is: class B : public A_template. :-)

        E Offline
        E Offline
        eusto
        wrote on last edited by
        #3

        assignment operator works like the constructor when it comes to inheritance. You should read more about this. Also read about: using A<T>::operator =; which should be placed in the declaration of B

        G 1 Reply Last reply
        0
        • E eusto

          assignment operator works like the constructor when it comes to inheritance. You should read more about this. Also read about: using A<T>::operator =; which should be placed in the declaration of B

          G Offline
          G Offline
          Green Fuze
          wrote on last edited by
          #4

          Thanks :-) I read about what you said, and I understand why the copy assignment is not being derived, but I can't find anything about the "using A::operator =;". Can I tell c++ explicitly that I want to use the operator at the base class?

          E 1 Reply Last reply
          0
          • G Green Fuze

            Thanks :-) I read about what you said, and I understand why the copy assignment is not being derived, but I can't find anything about the "using A::operator =;". Can I tell c++ explicitly that I want to use the operator at the base class?

            E Offline
            E Offline
            eusto
            wrote on last edited by
            #5

            just put that line in your B implementation and it should work

            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