C++ Library containing a lot of needful things: Stack Trace, Command Line Parser, Resource Handling, Configuration Files, Unix Command Execution, Directories, Regular Expressions, Tokenizer, Function Trace, Standard Extensions.
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
633 B
27 lines
633 B
13 years ago
|
#include <mrw/smartpointer.hxx>
|
||
21 years ago
|
|
||
|
class A {
|
||
|
public: int a;
|
||
11 years ago
|
public: virtual ~A() {}
|
||
21 years ago
|
protected: virtual void fn() {} // dynamic_cast requires a virtual function
|
||
|
};
|
||
|
|
||
|
class B: virtual public A {
|
||
|
public: int b;
|
||
|
};
|
||
|
|
||
|
int main(int, char**) {
|
||
13 years ago
|
mrw::SmartPointer<int> i1 = new int;
|
||
21 years ago
|
*i1 = 13;
|
||
13 years ago
|
mrw::SmartPointer<int> i2 = i1;
|
||
|
mrw::SmartPointer<int> i3;
|
||
21 years ago
|
if (!i3) i3 = i2;
|
||
|
*i2 = 666; // *i1 is now 666 too
|
||
13 years ago
|
mrw::SmartPointer<A> b1 = new B;
|
||
|
mrw::SmartPointer<B> b2 = b1; // b1 and b2 point to the same instance
|
||
21 years ago
|
b1->a = 0; // b1->b does not compile
|
||
|
b2->a = 1;
|
||
|
b2->b = 2;
|
||
|
return 0;
|
||
|
} // memory is automatically freed
|