[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-multimedia
Subject:    Re: adding properties to a C++ class
From:       ramagnus () t-online ! de (Rolf Magnus)
Date:       2001-12-17 11:34:07
[Download RAW message or body]

On Monday 17 December 2001 07:18, Scott Wheeler wrote:

> Is there any way to make a subclass function as a the baseclass even though
> it has more features?
> Is there any way to allow class quux to accept assignment from foo?

#include <iostream>
 
class foo {
 private:
   int myInt;
 public:
   int value() { return(myInt); }
   void setValue(int value) { myInt=value; }
 };
 
class baz : public foo {}; 

int main() 
{
   foo* bar = new baz;
   bar.setValue(3);
   cout << bar.value() << endl;
   baz* quux;
   quux = static_cast<baz*>(bar);
   cout << quux->value() << endl;
   return(0);
}

To cast the objects themselves you need a proper copy constructor.
_______________________________________________
kde-multimedia mailing list
kde-multimedia@mail.kde.org
http://mail.kde.org/mailman/listinfo/kde-multimedia
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic