User Profile

Collapse

Profile Sidebar

Collapse
kostocka
kostocka
Last Activity: Feb 19 '08, 10:37 PM
Joined: Mar 14 '07
Location:
  •  
  • Time
  • Show
  • Source
Clear All
new posts

  • kostocka
    replied to casting abstract classes
    in C
    yes, it is. What is even more weird is that if I declare 'int temp' instead, it works fine. I finally got everything to work by declaring 'new Derived'. If someone can explain to me why this makes sense, that would be great, otherwise the thread can be considered closed. Here is the working code in case somebody else cares:

    Code:
    class Base {
      string temp;
    public:
      virtual void whoami() = 0;
    };
    ...
    See more | Go to post

    Leave a comment:


  • kostocka
    replied to casting abstract classes
    in C
    yes, I realize that. I'm omitting some safety checks to keep the example short. Clearly, t is initialized here, it goes Ka-Boom anyway, but only if I uncomment line 10....
    See more | Go to post

    Leave a comment:


  • kostocka
    replied to casting abstract classes
    in C
    Thanks! The pointer did the trick (mostly). The following works as expected:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class Base {
    public:
    //   string temp;
      virtual void whoami() = 0;
    };
    
    class Derived1 : public Base {
    public:
      virtual void whoami()
    ...
    See more | Go to post

    Leave a comment:


  • kostocka
    replied to casting abstract classes
    in C
    yes, sorry, I meant to write:

    Code:
    class Derived1 : public Base {
    
    }
    class Derived2 : public Base {
    
    }
    ...
    See more | Go to post

    Leave a comment:


  • kostocka
    started a topic casting abstract classes
    in C

    casting abstract classes

    Dear gurus,

    I have been reading about polymorphism and generally think that I get the idea. At least I've gotten some code to work. Now I'm trying to get a little fancier and can't seem to figure out the following dilemma.

    I have an abstract class Base, and some Derived classes:

    Code:
    class Base {
    public:
    	void f1 () {
                  //....
            }
    	
      	virtual
    ...
    See more | Go to post
No activity results to display
Show More
Working...