Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class base {
- public:
- base()
- {
- std::cout << "foo is " << foo() << std::endl;
- }
- virtual int foo() { return 42; }
- };
- class derived : public foo {
- int* ptr_;
- public:
- derived(int i) : ptr_(new int(i*i)) { }
- // The following cannot be called before derived::derived due to how C++ behaves,
- // if it was possible... Kaboom!
- virtual int foo() { return *ptr_; }
- };
- type
- TComponent = class
- public
- constructor Create(AOwner: TComponent); virtual; // virtual constructor
- end;
- TMyEdit = class(TComponent)
- public
- constructor Create(AOwner: TComponent); override; // override virtual constructor
- end;
- TMyButton = class(TComponent)
- public
- constructor Create(AOwner: TComponent); override; // override virtual constructor
- end;
- TComponentClass = class of TComponent;
- function CreateAComponent(ComponentClass: TComponentClass; AOwner: TComponent): TComponent;
- begin
- Result := ComponentClass.Create(AOwner);
- end;
- var
- MyEdit: TMyEdit;
- MyButton: TMyButton;
- begin
- MyEdit := CreateAComponent(TMyEdit, Form) as TMyEdit;
- MyButton := CreateAComponent(TMyButton, Form) as TMyButton;
- end;
Add Comment
Please, Sign In to add comment