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. Classes hierarchy?

Classes hierarchy?

Scheduled Pinned Locked Moved C / C++ / MFC
questionc++htmlooptutorial
2 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.
  • V Offline
    V Offline
    Vaclav_
    wrote on last edited by
    #1

    I am trying to come up with “calling scheme” to be able to go "from top to bottom". For example “clear LCD device” via I2C interface and connected to GPIO. The “clear sequence from “top” is to send device specific command - “clear” output binary values of “clear command ” to SDA/SCL interface output binary values to GPIO I have a 3 levels basic / working inheritance scheme - with class representing the device , class representing I2C communication format and class representing the GPIO. I am not sure plain direct inheritance of chain of classes is going to do the job. I think I need to come up with “nesting” scheme instead of just plain direct inheritance chain using only instance of the “top” class. Any suggestions will be appreciated. Something like this, but it looks too scary http://www.linuxtopia.org/online\_books/programming\_books/c++\_practical\_programming/c++\_practical\_programming\_254.html Cheers Vaclav PS Please do not ask for code or "what is it for ? " , this project is under construction and not ready for public scrutiny.

    R 1 Reply Last reply
    0
    • V Vaclav_

      I am trying to come up with “calling scheme” to be able to go "from top to bottom". For example “clear LCD device” via I2C interface and connected to GPIO. The “clear sequence from “top” is to send device specific command - “clear” output binary values of “clear command ” to SDA/SCL interface output binary values to GPIO I have a 3 levels basic / working inheritance scheme - with class representing the device , class representing I2C communication format and class representing the GPIO. I am not sure plain direct inheritance of chain of classes is going to do the job. I think I need to come up with “nesting” scheme instead of just plain direct inheritance chain using only instance of the “top” class. Any suggestions will be appreciated. Something like this, but it looks too scary http://www.linuxtopia.org/online\_books/programming\_books/c++\_practical\_programming/c++\_practical\_programming\_254.html Cheers Vaclav PS Please do not ask for code or "what is it for ? " , this project is under construction and not ready for public scrutiny.

      R Offline
      R Offline
      Rick York
      wrote on last edited by
      #2

      I would advise you to try some experiments. It can be very simple. Write a simple class hierarchy with derived classes and have them call a virtual method each of them implements. Within the method, have it output a trace statement (TRACE, printf, cout<<, what ever...) You will see the calling sequence by the order of the output. One thing to be careful of is the order of the calls :

      virtual void TestMethod( int n )
      {
      __super::TestMethod( n+1 ); // call base class
      trace( _T( "in TestMethod( %d )\n" ), n );
      }

      // versus : (base class first or base class second)

      virtual void TestMethod( int n )
      {
      trace( _T( "in TestMethod( %d )\n" ), n );
      __super::TestMethod( n+1 ); // call base class
      }

      The output will show you which comes first. Implement as many derivation levels as you want, at least three I think. The base class won't have a __super so you will have to comment that off for it. Anyway, I recommend that you try this experiment. It doesn't take long and it is very informative.

      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