- 浏览: 389167 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (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)
最新评论
In my previous post - we have discussed on the topic of c++ - copy constructor and the initializer constructor in container and array.
Now, since we have conver the destructor and construcotr , we know there is default constructor, copy constructor, constructor that is marked explicit, and we know a single argument constructor can be be think of the conversion constructor...
now let's revisit the array/object initializer...below is the code and the comment inside it shall be enough to tell the key point of the object initializer ....
/** * file * array_initializer.cpp * description: * This shows how to use the array initializer to apply the array initialization */ #include "stdafx.h" #include "acct.h" #include <iostream> using std::cout; using std::endl; using std::cerr; void test_array_initializer() { cout << "initialize with the default single argument" << endl; // if object only has one single explicit constructor argument ,you can do this Account pooh_pals_single_args[] = { "piglet", "Eeyore", "Tigger" }; // and of course, if you want to specify mutiple arguments, here is the way // ther is one misunderstood in that // if will first call the // Account ("piglet", 1000.0); // and then the copy constructor will be called // Account(const Account & rhs); // the misconcept is that it will first create the temporary objects, which are // in the { ... } // block, then pooh_pals_mutiple_args will be invoked to get the right object contructed. // cout << "initialize with the multiple arguments" << endl; Account pooh_pals_multiple_args[] = { Account("piglet", 1000.0), Account("Eeyore", 1000.0), Account("Tigger", 1000.0) }; // if you want to initialize some with the default constructor, here is the way how you do it cout << "initialize with the multiple arguments mixed with default argument" << endl; Account pooh_pals_multiple_args_with_default_constructor[] = { Account("piglet", 1000.0), Account("Eeyore", 1000.0), Account(), }; // and if you specify the size, but in the initializer list, there is no insufficient number of // object in the initializer list, // then the default constructor will be called cout << "Default constructor will be called if the initializer list number is smaller than the array/contaier size" << endl; Account pooh_pals_multiple_args_with_insufficient_objects[3] = { Account("piglet", 1000.0), Account("Eeyore", 1000.0), }; // while if you are calling the new opertor, there is no way to specify the initializer with arguments cout << "default constructo will be called new operator on the heap" << endl; Account * pact = new Account[10]; // delete[] pact; }
and below is the definition of the Account class's header file.
class Account { public: /* ================= * ctor and dtors ========================*/ Account(); // since a constructor that takes only a single parameter can serves as a conversion operator // we don't want tripwire people into the trap of // Account acct = "new user"; // to help curb/reign this kind of unwantted/unwelcome compiler aid, the explicit keyword is introduced // //explicit //Account(const char *, double = 0.0); // for the purpose of demo the use of the array initalizer, we decide to use the implicit constructor approach Account(const char *, double = 0.0); // the copy constructor // the most important thing about the copy constructor is to decide whether or not to provide the copy constructor // the how as to implements the copy constructor comes seconds Account(const Account & ); ~Account(); const char * name(); // ... }
发表评论
-
不安装Visual Studio,只用Windows SDK搭建VC环境
2013-12-31 21:52 15283首先你需要下载的是 Microsoft Windows S ... -
rpath - runtime search path
2013-04-03 11:36 964RPath 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 919As in my prevoius example in j ... -
c++ -typeid operator
2012-10-15 22:30 1031typeid is the one of the meager ... -
c++ - dynamic_cast revisit
2012-10-14 21:21 735There are several built-in type ... -
c++ - virtual inheritance example 1
2012-10-14 15:25 783we have discussed the virtual i ... -
c++ - virtual inheritance
2012-10-12 08:58 913As we have discussed in the pos ... -
c++ type of inheritance
2012-09-28 08:58 721There are 3 types of inheritanc ... -
c++ - vritually virtual new
2012-09-27 23:59 930Let's see what if we want to cl ... -
c++ - virtual destructor
2012-09-27 22:01 923As we all know that virtual des ... -
c++ - vritual function and default arguments
2012-09-27 08:56 949As we all know that we virtual ... -
c++ - template specialization and partial specialization
2012-09-26 22:38 1285in this post, we are going to e ... -
c++ - member template in class template
2012-09-26 08:19 902class member template can be us ... -
c++ template class and the pattern to use its friends
2012-09-25 23:47 956template class may defined thei ... -
c++ - Friend declaration in class Template
2012-09-25 08:47 1179There are three kinds of friend ... -
c++ - class template default parameters
2012-09-25 08:18 799the template has parameter, it ... -
c++ - operator new and delete and an example of linked list stores by new/delete
2012-09-24 07:53 553The operator new and delete ope ... -
c++ - delete(void *, size_t) or delete(void *)
2012-09-24 07:18 1132In my previous dicuss, we have ... -
c++ - placement operator new() and the operator delete()
2012-09-23 15:22 836A class member operator new() c ...
相关推荐
of-Line Puzzle Binary I/O Buffering Problems Unbuffered I/O Designing File Formats C-Style I/O Routines C-Style Conversion Routines C-Style Binary I/O C- Versus C++- Style I/O Programming Exercises ...
This patch addresses a number of issues in RAD Studio 10.4, pertaining to Delphi Compiler, the RAD Studio IDE in general and the new LSP-based Code Insight in particular, plus C++ Builder Android ...
- Access to any object inside your application (in case you've allowed this). Standard libraries to access to base classes, controls and forms. Easily expandable library architecture. - Debugger....
Perhaps because web service clients are usually written in dynamic languages these days, none of the existing C++ JSON parsers fitted my needs very well, so I wrote one that I used in another project....
GETOPT C - Parses options in command line GREP2MSG C - Example program for Turbo C++ filters HELLO C - Example Turbo C++ program INTRO1 CPP - Example program from User's Guide INTRO10 CPP - ...
C++ How to Program presents leading-edge computing technologies in a friendly manner appropriate for introductory college course sequences, based on the curriculum recommendations of two key ...
Header Files The #define Guard Header File Dependencies Inline Functions The -inl.h Files Function Parameter Ordering Names and Order of Includes Scoping Namespaces Nested Classes Nonmember, Static ...
1.1 C++模式模式(The C++ Object Model) 简单对象模型(A Simple Object Model) 表格驱动对象模型(A Table-driven Object Model) C++对象模型(The C++ Object Model) 对象模型如何影响程序(How the Object ...
Cannot modify a const object ---------------不允许修改常量对象 Case outside of switch ----------------漏掉了case 语句 Case syntax error ------------------ Case 语法错误 Code has no effect ---------...
- ADD: In the module FlexUtils added the constant BooleanWords - an array containing the words 'false' and 'true' for saving/reading TBoolProp. - ADD: In the module FlexUtils added the function ...
CAJUN* is a C++ API for the JSON object interchange format. JSON is like XML, except it doesn't suck**. It is specifically designed for representing (in plain text format) structures familiar to ...
a powerful N-dimensional array object sophisticated (broadcasting) functions tools for integrating C/C++ and Fortran code useful linear algebra, Fourier transform, and random number capabilities ...
support for the newer C++ array operators, new[] and delete[]. “C” callable allocation routines are supplied, including malloc()/free(). These routines are compatible in real-time with the C++ new ...
丰富的类库,本产品提供常用的数据结构,例如List, Queue, Qegue, Stack, Array. . 等。 12.丰富的函数库:本产品提供4, 5百个函数,可以说无所不包了。 1.2.1. Borland C++3.1新功能 1. 3.1版将Turbo C++ for ...
// A C++ Program without class and object! #include using namespace std; const int N=200; void strUpper(char *s); void strLower(char *s); int main(){ char ms[N]; cout; cin.getline(ms,N); ...
a powerful N-dimensional array object sophisticated broadcasting functions basic linear algebra functions basic Fourier transforms sophisticated random number capabilities tools for integrating ...
I see many of those students now moving to C++ in their school work or career. The C++ language is becoming an industry-accepted standard programming language, using the solid foundation of C to gain ...
1.1 C++模式模式(The C++ Object Model) 简单对象模型(A Simple Object Model) 表格驱动对象模型(A Table-driven Object Model) C++对象模型(Th e C++ Object Model) 对象模型如何影响程序(How the Object ...
1.1 C++模式模式(The C++ Object Model) 简单对象模型(A Simple Object Model) 表格驱动对象模型(A Table-driven Object Model) C++对象模型(Th e C++ Object Model) 对象模型如何影响程序(How the Object ...