1,智能指针:auto_ptr(c++11 已经弃用),unique_ptr(用于取代 auto_ptr),  shared_ptr,  weak_ptr

  http://www.cnblogs.com/TenosDoIt/p/3456704.html(值得一看)

  https://blog.csdn.net/zhourong0511/article/details/80315961(优缺点分析)

 // classTest.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include <iostream>
#include <string>
#include <memory> using namespace std; class Test
{
public:
Test(string s);
~Test();
string& getStr();
void setStr(string s);
void print(); private:
string str;
}; Test::Test(string s)
{
str = s;
cout << "Test creat" << endl;
}
Test::~Test()
{
cout << "Test delete:" << str << endl;
}
string& Test::getStr() {
return str;
}
void Test::setStr(string s) {
str = s;
}
void Test::print() {
cout << str << endl;
} // unique_ptr 使用
unique_ptr<Test> fun() {
return unique_ptr<Test>(new Test(""));
} int _tmain(int argc, _TCHAR* argv[])
{
cout << "==========unique_ptr===========" << endl; unique_ptr<Test> ptest(new Test(""));
unique_ptr<Test> ptest2(new Test(""));
ptest->print(); //
ptest2 = move(ptest); // ptest == null,ptest2 原内容释放,ptest2 接管ptest
if (ptest == nullptr)
cout << "ptest == nullptr" << endl;
Test* p = ptest2.release(); // 可能有返回值,返回当前指向的内存空间
p->print(); //
ptest.reset(p);
ptest->print();
ptest2 = fun();
ptest2->print();
cout << "===========shared_ptr===========" << endl;
shared_ptr<Test> sptest(new Test(""));
shared_ptr<Test> sptest2(new Test(""));
cout << sptest2->getStr()<< endl;
cout << sptest2.use_count() << endl;
sptest = sptest2; // "456"引用次数 +1,"123" 引用次数 -1(此时为 0 ,被销毁)
sptest->print(); //
cout << sptest2.use_count()<< endl; // 此时引用数为2
cout << sptest.use_count() << endl;// 指向资源的引用数 为 2
sptest.reset(); //引用数 -1
sptest2.reset(); //引用数 -1 ,此时为 0 ,被销毁
cout << "done" << endl;
system("pause");
return ;
}

smart pointer

2,智能指针的不足和缺陷:

  https://www.zhihu.com/question/61008381

3,C++11 新特性:

  http://www.cnblogs.com/George1994/p/6684989.html(值得一看)

4,虚继承,虚函数表:

  https://www.cnblogs.com/fanzhidongyzby/archive/2013/01/14/2859064.html(值得一看)

5,C 内存模型:

  https://blog.csdn.net/anyaas/article/details/17099377

  C++ 内存模型:

  https://www.cnblogs.com/findumars/p/5929831.html?utm_source=itdadao&utm_medium=referral(值得一看)

6,如果在一个函数内定义一个 static 对象,什么时候执行构造和析构函数,如果这个函数从没被调用,会怎么被析构?

 #include <iostream>
#include <string>
#include <memory> using namespace std; class Test {
public:
Test() {
cout << "Constructor is executed" << endl;
}
~Test() {
cout << "Destructor is executed" << endl;
}
}; void myfunc() {
static Test obj;
} int main()
{
cout << "main() starts" << endl;
myfunc();
cout << "main() terminates" << endl; system("pause");
return ;
}
/* 输出结果
main() starts
Constructor is executed
main() terminates
请按任意键继续. . .
Destructor is executed
*/

static obj in function

分析:执行函数时,首先调用构造函数,但函数结束并不会调用析构函数,因为此对象 是 static 并不会被销毁,可以看到,在主函数退出之后,执行了析构函数。

 #include <iostream>
#include <string>
#include <memory> using namespace std; class Test {
public:
Test() {
cout << "Constructor is executed" << endl;
}
~Test() {
cout << "Destructor is executed" << endl;
}
}; //
void myfunc() {
static Test obj;
} int main()
{
cout << "main() starts" << endl;
// myfunc(); // 并不调用函数
cout << "main() terminates" << endl; system("pause");
return ;
}
/* 输出结果
main() starts
main() terminates
请按任意键继续.
*/

not invoke function

分析:当不调用函数时,构造函数和析构函数都不会执行(有点奇怪。)

7,C++ 11 左值和右值

  https://blog.csdn.net/chy19911123/article/details/46013499

8,STL 中容器的线程安全问题

  https://stackoverflow.com/questions/5912539/stl-map-find-thread-safe

9,为什么不要在构造函数/析构函数中调用虚函数?

  https://blog.csdn.net/xiaoqi2008/article/details/39371191

10,malloc设计的系统调用?

  https://blog.csdn.net/Always__/article/details/50990838

11,构造函数为什么不能是虚函数?

  https://blog.csdn.net/jiadebin890724/article/details/7951520

12,内存对齐以及如何关闭内存对齐?

  https://blog.csdn.net/a1205137569/article/details/48968699

13,不用 static 怎么计数一个 const 函数被调用了几次?(一般用 static,全局变量来进行计数)

  https://blog.csdn.net/sillyboard/article/details/594244(用了 mutable)

14,函数模板与类模板的区别?

  https://blog.csdn.net/tingzhushaohua/article/details/75331860

15,C++构造函数参数列表与直接在构造函数中进行初始化有什么区别?

  https://www.zhihu.com/question/60546182

16,const 和 define 的区别?

  https://blog.csdn.net/yi_ming_he/article/details/70405364

17,类里面成员变量为什么不能用 memset() 来进行设置?会有什么问题?

  https://blog.csdn.net/sulongvc/article/details/6064013

18,什么情况下函数里面的参数变量不一样也能实现多态?

  还未得到合理解答。

c++ 面试题(C/C++/STL)的更多相关文章

  1. STL笔试面试题总结(干货)(转)

    STL笔试面试题总结 一.STL有哪些组件? STL提供六大组件彼此此可以组合套用: 1.容器容器就是各种数据结构,我就不多说,看看下面这张图回忆一下就好了,从实现角度看,STL容器是一种class ...

  2. C/C++ 经典面试题汇总

    面试题1:变量的声明和定义有什么区别 ? 为变量分配地址和存储空间的称为定义,不分配地址的称为声明.一个变量可以在多个地方声明,但是只在一个地方定义.加入extern修饰的是变量的声明,说明此变量将在 ...

  3. C++目录

    C++ lambda表达式 C++中如何设计一个类只能在堆或者栈上创建对象,面试题 C++之STL总结精华笔记 指针强制类型转换的理解 关于指针类型和指针类型转换的理解 C++继承种类 C++ 单例模 ...

  4. 面试题总结(三)、《STL源码剖析》相关面试题总结

    声明:本文主要探讨与STL实现相关的面试题,主要参考侯捷的<STL源码剖析>,每一个知识点讨论力求简洁,便于记忆,但讨论深度有限,如要深入研究可点击参考链接,希望对正在找工作的同学有点帮助 ...

  5. 《STL源码剖析》相关面试题总结

    原文链接:http://www.cnblogs.com/raichen/p/5817158.html 一.STL简介 STL提供六大组件,彼此可以组合套用: 容器容器就是各种数据结构,我就不多说,看看 ...

  6. STL标准库面试题(转)

    一.vector的底层(存储)机制 二.vector的自增长机制 三.list的底层(存储)机制 四.什么情况下用vector,什么情况下用list 五.list自带排序函数的排序原理 六.deque ...

  7. [C++] STL相关面试题

    (1) 为何map和set的插入删除效率比用其他序列容器高? 因为map和set的内部数据结构是红黑树,它的插入和删除不需做内存的拷贝和移动.(红黑树的插入和删除是log(n)的). (2) 为何每次 ...

  8. C++常考面试题汇总

    c++面试题 一 用简洁的语言描述 c++ 在 c 语言的基础上开发的一种面向对象编程的语言: 应用广泛: 支持多种编程范式,面向对象编程,泛型编程,和过程化编程:广泛应用于系统开发,引擎开发:支持类 ...

  9. C/C++ 笔试题

    /////转自http://blog.csdn.net/suxinpingtao51/article/details/8015147#userconsent# 微软亚洲技术中心的面试题!!! 1.进程 ...

随机推荐

  1. js 功能

    ---IE wps excelApp =ActiveXObject("Excel.Application") App.DisplayAlerts = false 不显示警告 App ...

  2. PythonStudy——元组 Tuple

    元组类型 元组:可以理解为不可变的列表1.值可以为任意类型2.可以存放多个值 - 可以进行成员运算3.可以存放重复的值 - 可以计算成员出现的次数4.有序存储 - 可以通过索引取值,可以切片 常用操作 ...

  3. java多线程同步器

    Java中多线程开发时,离不开线程的分工协作,常用的多线程的同步器有如下几种: 1.CountDownLatch 应用场景:等待一组线程任务完成后在继续执行当前线程. 用法:定义一个CountDown ...

  4. centos 7.x开放端口

    1. 查看已打开的端口 # netstat -anp 2. 查看想开的端口是否已开 # firewall-cmd --query-port=666/tcp 若此提示 FirewallD is not ...

  5. koa2+log4js+sequelize搭建的nodejs服务

    主要参考http://www.jianshu.com/p/6b816c609669这篇文章 npm安装使用国内taobao镜像,速度更快些 npm --registry https://registr ...

  6. 为嵌入式mplayer移植添加ALSA音频驱动(全志V3s荔枝派zero)

    首先准备mplayer和alsa_lib,我的是bulidroot添加后编译自动下载的,版本分别是alsa-lib-1.1.4.1和mplayer-1.3.0. 首先编译alsa_lib: ./con ...

  7. 【ELK】之Centos6.9_x64安装elasticsearch6.2.1

    1.下载elasticsearch6.2.1 wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.1 ...

  8. problem:浏览器如何区分html超文本和普通文本

    运营同学问:后端返回的一串元素标签,我想在网页中显示的时候,将标签中的内容渲染出来,不希望直接显示标签. 回答:bootstrap加模版组织的网页,模版渲染的数据只能渲染字符串,不能转化富文本. 运营 ...

  9. SQLServer、MySQL、Oracle如何查看所有表的条数

    SQLServer: create table #t(name varchar(255), rows bigint, reserved varchar(20), data varchar(20), i ...

  10. 华硕R系列的解剖图

    1.键盘底部 2.右侧光驱,右下硬盘 3.电源 4.主板 5. 6.4G内存