- 浏览: 397961 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (309)
- xaml C# wpf (0)
- scala java inner clas (1)
- Tools UML Eclipse UML2 (1)
- Timer .NET Framework (1)
- perl (6)
- python function paramter (1)
- Python Docstring (1)
- Python how to compare types (1)
- Python (8)
- java (5)
- C# (76)
- C# WPF (0)
- p4 (0)
- WPF (46)
- .net (6)
- xaml (1)
- javascript (40)
- windows (10)
- scala (4)
- winform (1)
- c++ (48)
- tools (12)
- cmd (1)
- os (0)
- CI (0)
- shell (0)
- C (2)
- haskell (49)
- functional (1)
- tool (1)
- gnu (1)
- linux (1)
- kaskell (0)
- svn (0)
- wcf (3)
- android (1)
最新评论
How do we duplicate a object through its pointer or reference? suppose
NotQuery *pnq;
NotQuery *pnq2 = new NotQuery(*pnq);
however, what if we have this ?
const Query *pq = pnq->op();
// ???
we cannot dclare a virutal new instance of operator new, the new operator is a static member, and it applies before the constructor.
THINK:??? you can overload new operator inside the class, , however, we cannot make it virtual still it does not answer the time/order problem.
the solution is a surrogate, somehting like this:
public Query { public: virtual Query * clone() = 0; };
however, if we cannot change the return type in the derived class, then we might see this
NameQuery *png = new NameQuery("Rike"); NameQuery *pnq2 = static_cast<NameQuery*> (pnq->clone());
BUT!!!,there is an exception to that "requirement that return type of the derived class must match exactly that of the base class".
so, in the derived class, you can write
public NameQuery : public Query { public: virtual NameQuery* clone() { return new NameQuery(*this); } };
Below shows the whole code ::
class Base { public : Base() { } Base(Base &base) {} virtual Base *clone(); protected: Base *print(); private: }; class Derived : public Base { public: Derived() {} Derived (Derived &derived) : Base(derived) {} virtual Derived *clone(); protected: Base *print(); }; Base* Base::clone(){ return new Base(*this); } Derived* Derived::clone() { return new Derived(*this); }
发表评论
-
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15331首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 1005RPath is a very interesting to ... -
C++ - autogenerated copy constructor and assignment operator gotchas
2013-01-24 13:32 765It has been changed that the s ... -
c++ - rethrow a exception gotchas
2012-12-23 10:57 948As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1055typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 764There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 813we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 969As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 747There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 958Let's see what if we want to cl ... -
c++ - virtual destructor
2012-09-27 22:01 972As we all know that virtual des ... -
c++ - vritual function and default arguments
2012-09-27 08:56 991As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1325in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 930class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 983template class may defined thei ... -
c++ - Friend declaration in class Template
2012-09-25 08:47 1205There are three kinds of friend ... -
c++ - class template default parameters
2012-09-25 08:18 847the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 582The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1158In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 861A class member operator new() c ...
相关推荐
operand to be an operation region of any type. It is now restricted to regions of type SystemMemory, as per the ACPI specification. BZ 481 Additional cleanup and optimizations for the new Table ...
Complete Virtual Reality and Augmented Reality Development with Unity by Jesse Glover Jonathan Linowes Packt Publishing English 2019-04-17 668 pages Details Title: Complete Virtual Reality and ...
In Modern C++ Design, Andrei Alexandrescu opens new vistas for C++ programmers. Displaying extraordinary creativity and virtuosity, Alexandrescu offers a cutting-edge approach to software design that ...
Chapter 1, Virtually Everything for Everyone, is an introduction to the new technologies and opportunities in consumer virtual reality (VR) as regards games and non-gaming applications. Chapter 2, ...
The latest version of our security components for Delphi and C++ Builder allows the developer to easily add password protection and access control to resources like Buttons, Menus, DBGrids, TFields ...
- The Drag and Drop API simplifies the implementation of drag-and-drop interactions, enhancing user engagement and interaction. 6. **Becoming Skilled in Contemporary Web Standards** - Staying ...
From type definition to error handling, this book presents C++ best practices, including some that have only recently been identified and standardized-techniques you may not know even if you've used ...
DESCRIPTION There's a virtual switchboard at the heart of most large applications, where millions of messages and requests need to be routed to and from the servers, programs, and services that make ...
DESCRIPTION There's a virtual switchboard at the heart of most large applications, where millions of messages and requests need to be routed to and from the servers, programs, and services that make ...
TFormStorage allows you to read and write virtually any component published property to an INI file or the system Registry with virtually no code. Works with 3rd party and your own custom controls as ...
DESCRIPTION There's a virtual switchboard at the heart of most large applications, where millions of messages and requests need to be routed to and from the servers, programs, and services that make ...
Pro JavaFX 9: A Definitive Guide to Building Desktop, Mobile, and Embedded Java Clients also contains engaging tutorials that cover virtually every facet of JavaFX development and reference materials...