我正在尝试声明纯虚拟析构函数,在VS2019中我这样写:
virtual ~A() = 0 {};
Run Code Online (Sandbox Code Playgroud)
很好,但是在Clion中,我接受了以下消息:
函数定义虚拟的纯说明符〜A()= 0 {};
并且迫使我为该函数编写不同的实现(不是给它带来很多麻烦,而是我想知道为什么会这样)
我试过这个
{
std::function<void(int)> push;
queue<int> myqueue;
push = std::bind(static_cast<void (queue<int>::*)(int)>(&queue<int>::push), &myqueue,std::placeholders::_1);
push(8);
}
Run Code Online (Sandbox Code Playgroud)
但它不起作用
我有一个文件,我想使用 grep 命令解析,该文件由如下行组成:
NVO,0,267,61,247357,247357,O,19:00:00.000000,06:09:08.417320,07:55:22.068670
DVD,0,267,61,247357,247357,O,19:00:00.000000,06:09:08.417320,07:55:22.068670
NVO,0,267,61,247358,247358,B,19:00:00.000000,06:09:08.417407,07:55:22.079291
DVD,0,267,61,247358,247358,B,19:00:00.000000,06:09:08.417407,07:55:22.079291
Run Code Online (Sandbox Code Playgroud)
我只想获取以 NVO 开头且有 ,B, 的行。输出应该是这样的:
NVO,0,267,61,247358,247358,B,19:00:00.000000,06:09:08.417407,07:55:22.079291
Run Code Online (Sandbox Code Playgroud)
获取NVO,我正在使用的线路grep ^NVO, file_name.txt ,但我无法添加,B,
我尝试过的grep '^NVO,|,B,' file_name.txt第二个条件
grep ",B," | grep "^NVO," file_name.txt
Run Code Online (Sandbox Code Playgroud)
不幸的是,我知道我可以用两个命令来做到这一点,第一个命令写入文件,然后使用过滤器执行第二个 grep,B,命令
我有矢量
std::vector<OrderInfo *> vec
Run Code Online (Sandbox Code Playgroud)
和一个队列
queue<OrderInfo *> *myQueue = new queue<OrderInfo *>;
Run Code Online (Sandbox Code Playgroud)
我想将向量复制到队列中。我尝试使用如何将整个向量复制到队列中?这个答案以及这个使用 std::copy 插入到 STL 队列中
但它不起作用,我该如何使它起作用?
这是我试过的: myQueue = new queue(vec.begin(), vec.end()); 我有
错误:没有匹配的函数调用'std::queue::queue(std::vector::iterator, std::vector::iterator)' myQueue = new queue(vec.begin(), vec.end() );
当我尝试这个时:
std::copy(vec.begin(),vec.end(),std::back_inserter(myQueue));
Run Code Online (Sandbox Code Playgroud)
我有:
来自 'BacStrategy::BacStrategy(EZXConnectionHandler&, const string&, bool, const double&, int) [with Event_Type = EZXOrderEventHandler; std::__cxx11::string = std::__cxx11::basic_string]' /home/yaodav/Desktop/git_repo/test/main.cpp:324:51:从这里 /usr/local/include/c++/7.4 需要。 0/bits/stl_iterator.h:490:7: 错误:'std::queue*' 不是类、结构或联合类型 operator=(const typename _Container::value_type& __value)
当我在此处输入链接描述中运行以下代码 并且当擦除是预成型时迭代器被提升(迭代器前进到下一个元素)而在我的真实代码中它不是(我知道它不应该提升我的迭代器,当我使用擦除时,迭代器变得无效)但为什么在模拟器上会发生?
*编辑这是代码:
// Example program
#include <iostream>
#include <string>
#include <vector>
struct A {
A(int _a):a{_a}{}
int a;
};
struct B {
B()
{
vec.push_back(new A(1));
vec.push_back(new A(2));
}
std::vector<A*> vec;
void clean()
{
for(auto e = vec.begin(); e != vec.end(); )
{
auto it = *e;
std::cout << it->a << std::endl;
vec.erase(e);
}
std::cout << vec.size() << std::endl;
}
};
int main()
{
B b;
b.clean();
return 0;
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 boost 1.75.0,我正在尝试更新我的服务器,以便他可以同时监听两个不同的端口,比如说IP 127.0.0.1 port 6500 and port 6600.
我需要保留Server两个套接字吗?这是我的服务器
#include <boost/asio/io_service.hpp>
#include <boost/asio.hpp>
#include <queue>
#include "Session.h"
using boost::asio::ip::tcp;
class Server
{
public:
Server(boost::asio::io_service &io_service, short port)
: acceptor_(io_service, tcp::endpoint(tcp::v4(), port)),
socket_(io_service)
{
do_accept();
}
private:
void do_accept(){
acceptor_.async_accept(socket_,
[this](boost::system::error_code ec) {
if (!ec) {
std::cout << "accept connection\n";
std::make_shared<Session>(std::move(socket_))->start();
}
do_accept();
});
}
tcp::acceptor acceptor_;
tcp::socket socket_;
};
Run Code Online (Sandbox Code Playgroud)
这是我的课程
#include <boost/asio/io_service.hpp>
#include <boost/asio.hpp>
#include "message.h"
#include <fstream>
#include <boost/bind/bind.hpp>
namespace {
using boost::asio::ip::tcp;
auto constexpr …Run Code Online (Sandbox Code Playgroud) 我正在用 c 编写一个简单的程序,该程序有两个线程和两个全局变量,但 printf 函数不起作用,我知道这printf不是线程安全的,而且如果我\n在 print 中添加它会起作用,但我想要了解为什么没有它就无法工作?我正在添加代码,
#include <pthread.h>
#include <stdio.h>
int i;
int j;
void* runi(void* _temp)
{
while(1)
{
i++;
if(i==1000)
{
printf("i: %d",i);
}
}
return NULL;
}
void* runj(void* _temp)
{
while(1)
{
j++;
if(j==1000)
{
printf("j: %d",j);
}
}
return NULL;
}
main ()
{
pthread_t threadI,threadJ;
pthread_create(&threadI,NULL,runi,NULL);
pthread_create(&threadJ,NULL,runj,NULL);
pthread_join(threadI,NULL);
pthread_join(threadJ,NULL);
return 0;
}
Run Code Online (Sandbox Code Playgroud) 正如标题所述,我遇到了臭名昭著的unresolved external symbol链接器问题。
我已经移动了.h文件中的所有内容。模板类不再在.h和.cpp文件之间拆分。
我已将它们包含在主文件中。我已经三重四重检查了定义是否存在(显然)。
我的文件如下:
Utils.h:
只是一个漂亮的 coutvector和valarray。测试和工作。
#pragma once
#include <vector>
#include <valarray>
#include <ostream>
using std::vector;
using std::valarray;
using std::ostream;
template <typename ValueType>
ostream& operator<< (ostream&, vector<ValueType>);
template <typename ValueType>
ostream& operator<< (ostream&, valarray<ValueType>);
template <typename ValueType>
ostream& operator<< (ostream& out, vector<ValueType> v)
{
out << "Vec[";
for (int i = 0; i < v.size() - 1; i++)
out << v[i] << ", "; …Run Code Online (Sandbox Code Playgroud) c++ ×6
visual-c++ ×2
bash ×1
bind ×1
boost ×1
boost-asio ×1
c ×1
c++11 ×1
clion ×1
grep ×1
linker ×1
pure-virtual ×1
queue ×1
std-function ×1
stl ×1
templates ×1