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. User specified inheritance

User specified inheritance

Scheduled Pinned Locked Moved C / C++ / MFC
c++wpftestingbeta-testingoop
3 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.
  • J Offline
    J Offline
    John R Shaw
    wrote on last edited by
    #1

    I am reworking a template library that is VC++6.0 compatible, but I do not have access to that compiler at the moment. Will the following test successfully compile and run on VC++6.0?

    // JRS - 7.25.2010 - Test user specified inheritance
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    template<typename CharT>
    struct A
    {
    	CharT ch;
    	A() : ch('A') {}
    };
    
    template<typename CharT, typename BaseT = A<CharT> >
    struct B : public BaseT // user specified inheritance
    {
    	B() { BaseT::ch = 'B'; }
    };
    
    int main(int argc, char* argv[])
    {
    	A<char> a;
    	B<char> b;
    
    	cout << "a.ch = " << a.ch << endl;
    	cout << "b.ch = " << b.ch << endl;
    
    	system("PAUSE");
    	return 0;
    }
    

    Curious? I have 3 class templates that all have a “has-a” relationship with a data storage class template and I am changing it to an “is-a” relationship. But I still want the user to be able specify the storage class, as there are legitimate reasons why they may want to. The above method solves the problem, but I have never seen it used by anyone else.

    INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

    D 1 Reply Last reply
    0
    • J John R Shaw

      I am reworking a template library that is VC++6.0 compatible, but I do not have access to that compiler at the moment. Will the following test successfully compile and run on VC++6.0?

      // JRS - 7.25.2010 - Test user specified inheritance
      #include <cstdlib>
      #include <iostream>
      
      using namespace std;
      
      template<typename CharT>
      struct A
      {
      	CharT ch;
      	A() : ch('A') {}
      };
      
      template<typename CharT, typename BaseT = A<CharT> >
      struct B : public BaseT // user specified inheritance
      {
      	B() { BaseT::ch = 'B'; }
      };
      
      int main(int argc, char* argv[])
      {
      	A<char> a;
      	B<char> b;
      
      	cout << "a.ch = " << a.ch << endl;
      	cout << "b.ch = " << b.ch << endl;
      
      	system("PAUSE");
      	return 0;
      }
      

      Curious? I have 3 class templates that all have a “has-a” relationship with a data storage class template and I am changing it to an “is-a” relationship. But I still want the user to be able specify the storage class, as there are legitimate reasons why they may want to. The above method solves the problem, but I have never seen it used by anyone else.

      INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

      D Offline
      D Offline
      David Crow
      wrote on last edited by
      #2

      John R. Shaw wrote:

      Will the following test successfully compile...on VC++6.0?

      Yes.

      "One man's wage rise is another man's price increase." - Harold Wilson

      "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

      "Man who follows car will be exhausted." - Confucius

      J 1 Reply Last reply
      0
      • D David Crow

        John R. Shaw wrote:

        Will the following test successfully compile...on VC++6.0?

        Yes.

        "One man's wage rise is another man's price increase." - Harold Wilson

        "Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons

        "Man who follows car will be exhausted." - Confucius

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        Thanks! :-D

        INTP "Program testing can be used to show the presence of bugs, but never to show their absence." - Edsger Dijkstra "I have never been lost, but I will admit to being confused for several weeks. " - Daniel Boone

        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