20200708-头条,视频架构
问的很基础,但是回答的很稀烂
1. 允许多个进程同时对数据进行读操作,但是不允许读和写以及写和写操作同时发生。
一个整型变量 count 记录在对数据进行读操作的进程数量,一个互斥量 count_mutex 用于对 count 加锁,一个互斥量 data_mutex 用于对读写的数据加锁。
2.
用变量a 给出下面的定义
1) 一个有10个指针的数组,该指针是指向一个整型数的;
2) 一个指向有10个整型数数组的指针;
3) 一个指向函数的指针,该函数有一个整型参数并返回一个整型数;
4) 一个有10个指针的数组,该指针指向一个函数,该函数有一个整型参数并返回一个整型数;
3.
- const A* a和 A const* a的区别是?
- volatile、mutable分别怎么用,有什么区别?
- 在C++ 程序中调用被 C 编译器编译后的函数,需要怎么处理一下?为什么?
4 .带答案(请填充位置的函数体)
#include <iostream>
#include <cstring>
using namespace std;
class C
{
public:
C(int size) : i(size)
{
data = (char*)new char[i];
}
~C()
{
//请填充
if(data != NULL) {
delete []data;
}
}
C(const C& other) = delete;
C(C&& other) = delete;
C& operator=(const C& other)
{
// 请填充
if(this != &other)
return *this;
i = other.i;
if(data != NULL) {
delete [] data;
}
data = new char[i];
memcpy(data, other.data, i);
return *this;
}
C& operator=(C&& other)
{
//请填充
if(this != &other)
return *this;
i = other.i;
if(data = NULL)
delete [] data;
data = other.data;
// memcpy(data, other.data, i);
return *this;
}
private:
char* data;
int i;
}