Friday, March 30, 2012

Weekend Started, so I fixed this:

http://stackoverflow.com/questions/9939739/simple-polymorphism

so with some help from Stack Overflow (and Matt, one of my only commenters; HI MATT!) , I did this stuff:

 #include <iostream>  
 using namespace std;  
 class thing1  
 {  
 public:  
   virtual void thingTest()  
   {  
     cout << "I AM THING 1\n";  
   }  
 };  
 class thing2: public thing1  
 {  
 public:  
    void thingTest()  
   {  
     cout << "I AM THING 2\n";  
   }  
 };  
 void DoStuff( thing1 temp )  
 {  
   temp.thingTest();  
 }  
 void DoMoreStuff( thing1& temp )  
 {  
      temp.thingTest();  
 }  
 int main()  
 {  
      //these look more like a thing1  
   DoStuff( thing2() );  
      ( (thing1) thing2() ).thingTest();  
      //look like thing2s  
      thing2().thingTest();  
      DoMoreStuff( thing2() );  
 }  

This outputs:
I AM THING 1
I AM THING 1
I AM THING 2
I AM THING 2
so, now to make the LinkedList to store Queues of Thing1s that could actually be Thing2s. (my render system will work by letting the coder dump things into a "todo list" and render the whole list at once)

2 comments:

  1. it's always good to know how to implement lists and queues, but there's always the STL...

    doubly linked list
    http://www.cplusplus.com/reference/stl/list/

    double ended queue
    http://www.cplusplus.com/reference/stl/deque/

    also, it's Matt with 2 t's :)

    ReplyDelete
  2. I would just use the stl, but I don't know the platfrom this will run on, and then I don't know if that platform will support anything like that. I might port this thing to AGK at some point ( http://www.appgamekit.com/ ), so I want to use as little stdlib stuff as possible.

    ReplyDelete