小编kla*_*aus的帖子

C++将操作符放在类的末尾是什么意思?

假设我有一个名为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)

我通常在代码中发现我读了最后两条指令,但我真的不明白.是否必须正确使用该组件?

c++ operator-keyword

4
推荐指数
1
解决办法
216
查看次数

由于类类型的错误转换,无法通过此操作

我在两个不同的文件中定义了以下两个类:

#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++ this c++11

3
推荐指数
1
解决办法
46
查看次数

C++中不允许使用static/global变量

我在C++类中定义了一个全局变量,如下所示:

std::string VAR = "HELLO_WORLD";
Run Code Online (Sandbox Code Playgroud)

但是cpplint告诉我:

不允许使用静态/全局字符串变量.[runtime/string] [4]

你知道为什么吗?

c++ cpplint

1
推荐指数
1
解决办法
1283
查看次数

加入线程:“避免资源死锁”

我使用封装了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)

boost deadlock pthreads boost-asio

1
推荐指数
1
解决办法
3680
查看次数

CSS在里面有图像的div角添加圆形贴纸

我在 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)

html css

1
推荐指数
1
解决办法
786
查看次数

标签 统计

c++ ×3

boost ×1

boost-asio ×1

c++11 ×1

cpplint ×1

css ×1

deadlock ×1

html ×1

operator-keyword ×1

pthreads ×1

this ×1