假设我有一个名为Component的简单c ++组件,如下所示:
class Component {
public:
explicit Component(int i)
: _integer(i) {
}
~Component() {
}
private:
int _integer;
Component(const Component&);
Component& operator=(const Component&);
};
Run Code Online (Sandbox Code Playgroud)
我通常在代码中发现我读了最后两条指令,但我真的不明白.是否必须正确使用该组件?
我在两个不同的文件中定义了以下两个类:
#include "B.h"
class A {
public:
A() {}
~A() {}
f() {
auto b = new B(this);
}
};
Run Code Online (Sandbox Code Playgroud)
在另一个文件中:
#include "A.h"
class B {
public:
B(A* a) {}
~B() {}
}
Run Code Online (Sandbox Code Playgroud)
但我不明白我得到的编译错误:
B.h: error: ‘A’ has not been declared
A.cpp: error: no matching function for call to ‘B(A&)‘
*this);
note: candidate is:
note: B(int*)
note: no known conversion for argument 1 from ‘A’ to ‘int*’
Run Code Online (Sandbox Code Playgroud)
为什么我的A类已经转换为int?
我在C++类中定义了一个全局变量,如下所示:
std::string VAR = "HELLO_WORLD";
Run Code Online (Sandbox Code Playgroud)
但是cpplint告诉我:
不允许使用静态/全局字符串变量.[runtime/string] [4]
你知道为什么吗?
我使用封装了boost::asio::io_service的 c++ 类。
class IoService {
public:
static IoService& getInstance() {
static IoService instance;
return instance;
}
void start() {
_ioServiceThread = std::thread(&IoService::run, this);
}
void stop() {
_ioService.stop();
_ioServiceThread.join();
}
void run() {
_ioService.run();
}
private:
IoService();
~IoService();
IoService(const IoService& old) = delete;
IoService(const IoService&& old) = delete;
IoService& operator=(const IoService& old) = delete;
IoService& operator=(const IoService&& old) = delete;
boost::asio::io_service _ioService;
std::thread _ioServiceThread;
};
Run Code Online (Sandbox Code Playgroud)
但是当我调用 stop 方法时,程序在连接时崩溃:
terminate called after throwing an instance of 'std::system_error'
what(): …
Run Code Online (Sandbox Code Playgroud) 我在 html 页面中有以下块:
* {
margin: 0px;
padding: 0px;
box-sizing: border-box;
}
body, html {
height: 100%;
}
.container-form {
width: 100%;
min-height: 100vh;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
display: flex;
flex-wrap: wrap;
justify-content: center;
align-items: center;
padding: 15px;
}
.wrap-form {
width: 500px;
background: #fff;
border-radius: 10px;
overflow: hidden;
padding: 42px 55px 45px 55px;
}
<div class="container-form">
<div class="wrap-form">
<form> ... </form>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
我想在右上角添加一个带有图像的圆形贴纸。
我以包装形式创建了以下 div:
.sticker {
display: inline-block;
width: 250px;
height: 250px;
border-radius: …
Run Code Online (Sandbox Code Playgroud)