1.在C++中,基本数据类型有多少种初始化方式?你能都说出来吗?
1.直接初始化("()"):又叫做构造函数(constructor)初始化, 是将初始值用小括号(parenthesis ())括起来,
2.复制初始化("="):又叫做类C (c-like) 方法,是在声明变量的时候加上一个等于号
2.什么是复制构造函数,何时会用到?尤其是与赋值操作符相比,你能区分吗?
1.根据另一个同类型的对象显示或隐式初始化一个对象.
2.复制一个对象,将它作为实参传给一个函数(即给函数传入一个对象,会调用其复制构造函数).
3.从函数返回一个对象时,会调用其复制构造函数.
4.初始化顺序容器中的元素.
5.根据元素初始化列表初始化数组元素.(class a; a arr[]={.....};):数组中的每个元素使用复制初始化来初始化每个元素,
根据指定的值来创建适当的类型元素,然后用复制构造函数将改制复制到相应的元素
与赋值操作符相比,对于类类型的初始化而言(复制初始化),赋值操作符总是调用复制构造函数创建一个临时的对象,然后赋值到正在创建的对象中
复制构造函数,赋值操作符 与析构函数一般称为复制控制(Copy Control),而当一个类需要自定义复制构造函数时,一般而言我们几乎肯定也需要重载赋值操作符.
3.在C++中,何时适合通过引用来返回值,何时不适合?
4.为什么绝对不应该在析构函数中抛出异常?
- How many ways are there to initialize a primitive data type in C++ and what are they?
- Why should you declare a destructor as virtual?
- What does it mean that C++ supports overloading?
- What are examples of overloading in C++?
- What is name mangling in C++ and why is it used?
- What is an abstract base class?
- What is RTTI?
- How can you access a variable that is “hidden” by another variable of the same name?
- What is a namespace and how is it used.
- What are the differences between a class and a struct in C++, and how does this compare to C?
- What are templates? How are they used?
- What is a copy constructor and when is it used, especially in comparison to the equal operator.
- What is the difference between a “shallow” and a “deep” copy?
- What is the const operator and how is it used?
- What are the differences between passing by reference, passing by value, and passing by pointer in C++?
- When is it and when is it not a good idea to return a value by reference in C++?
- What is the difference between a variable created on the stack and one created on the heap?
- How do you free memory allocated dynamically for an array? What are the implications of just using delete?
- What is multiple inheritance? When should it be used?
- What is a pure virtual function?
- What does the keyword mutable do?
- What does the keyword volatile do?
- What is the STL?
- What is a Vector?
- What is contained in the <algorithms> header?
- What is the difference between #include <iostream.h> and #include <iostream>?
- What’s the difference between “++i” and “i++”?
- What is short circuit evaluation? How can it be used? Why can is be dangerous?
- What is the ‘,’ operator?
- What is the only ternary operator? How is it used?
- What is the use of a const member function and how can it be used?
- How is try/catch used in C++?
- Why should you never throw an exception in a destructor?
- What is the explicit keyword?
- What is the proper way to perform a cast in C++?
- What does inline do?