- 浏览: 389703 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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 15287首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 965RPath is a very interesting to ... -
C++ - autogenerated copy constructor and assignment operator gotchas
2013-01-24 13:32 744It has been changed that the s ... -
c++ - rethrow a exception gotchas
2012-12-23 10:57 922As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1033typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 738There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 784we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 914As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 723There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 931Let's see what if we want to cl ... -
c++ - virtual destructor
2012-09-27 22:01 926As we all know that virtual des ... -
c++ - vritual function and default arguments
2012-09-27 08:56 951As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1289in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 907class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 959template class may defined thei ... -
c++ - Friend declaration in class Template
2012-09-25 08:47 1183There are three kinds of friend ... -
c++ - class template default parameters
2012-09-25 08:18 806the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 555The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1136In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 839A 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 ...
Displaying extraordinary creativity and virtuosity, Alexandrescu offers a cutting-edge approach to software design that unites design patterns, generic programming, and C++, enabling programmers to ...
The C++ Standard Library is a collection of essential classes and functions used by millions of C++ programmers on a daily basis. Being part of the ISO Standard of the C++ Programming Language, an ...
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 ...
Based on the authors' intensive summer C++ courses at Stanford University, Accelerated C++ covers virtually every concept that most professional C++ programmers will ever use -- but it turns the '...
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 ...
Offering a comprehensive introduction to both the standard C++ language and to Visual C++, he offers step-by-step programming exercises, examples, and solutions to deftly guide novice programmers ...
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 ...
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 ...
To support, and perhaps further boost, this growth the Third Generation Partnership Project (3GPP) standards development organization has in its Release 13 developed three new technologies known as ...
With Hadoop 2.x and YARN, Hadoop moves beyond MapReduce to become practical for virtually any type of data processing. Hadoop 2.x and the Data Lake concept represent a radical shift away from ...