可能的重复:
vim:搜索替换所有可写缓冲区
我可以用:%s/foo/blah/g当前缓冲区中的“blah”替换所有出现的“foo”。我怎样才能同时在所有打开的缓冲区上执行此操作?
就C++ 11而言,我认为在至少两个线程之间共享的值 - 语义对象的副本不是线程安全的吗?
这意味着如果我们想在一个线程中获得一个大对象的副本,我们仍然需要一些同步机制来制作副本?
有没有办法消除Foo中的显式构造函数调用,并以某种方式将Bar :: len分配给Bar的任何子类的大小?
class Bar
{
size_t len_;
Bar(size_t len) : len_(len) { }
};
class Foo : public Bar
{
Foo() : Bar(sizeof(Foo)) { }
};
Run Code Online (Sandbox Code Playgroud) 有没有一种方法可以在C ++中创建哈希哈希?
实际上,我正在尝试做您可以在Perl中完成的工作,但仅限于C ++。这是我想在C ++中发生的Perl代码示例
%hash = (
gameobject1 => {
position => {
x_loc => 43,
y_loc => 59,
}
rect_size => {
width => 5,
height => 3,
}
collidable => 1,
sounds => {
attack => "player_attack.ogg",
jump => "player_jump1.ogg",
jump_random => [qw/player_jump1.ogg player_jump2.ogg player_jump3.ogg/]
}
},
gameobject2 => {
position => {
x_loc => 24,
y_loc => 72,
}
rect_size => {
width => 2,
height => 4,
}
sounds => {
attack => "goblin_attack.ogg",
} …Run Code Online (Sandbox Code Playgroud) 考虑以下:
class Example : boost::noncopyable
{
HANDLE hExample;
public:
Example()
{
hExample = InitializeHandle();
}
~Example()
{
if (hExample == INVALID_HANDLE_VALUE)
{
return;
}
FreeHandle(hExample);
}
Example(Example && other)
: hExample(other.hExample)
{
other.hExample = INVALID_HANDLE_VALUE;
}
Example& operator=(Example &&other)
{
std::swap(hExample, other.hExample); //?
return *this;
}
};
Run Code Online (Sandbox Code Playgroud)
我的想法是析构函数将很快在"其他"上运行,因此我不必通过使用swap在移动赋值运算符中再次实现我的析构函数逻辑.但我不确定这是一个合理的假设.这会"好"吗?
假设我有一个父类:
Class Parent{
public:
virtual void doSomething(){}
}
Run Code Online (Sandbox Code Playgroud)
和两个孩子:
Class Son: public Parent{
public:
void doSomething(){
// Do one thing
}
}
Class Daughter: public Parent{
public:
void doSomething(){
// Do another thing
}
}
Run Code Online (Sandbox Code Playgroud)
如果我像这样设置一个子类的实例:
Parent obj = Son();
Run Code Online (Sandbox Code Playgroud)
如何正确调用doSomething()由Son而不是空函数定义的方法Parent
#include <functional>
#include <iostream>
struct Test
{
void fnc(int & a) { ++a; }
};
int main ()
{
typedef std::function<void(int)> Func;
int i = 0;
Test t;
Func f = std::bind(&Test::fnc, &t, std::ref(i));
//f(); //error C2064: term does not evaluate to a function taking 0 arguments
f(37); //Here I am forced to pass evidently unused int
std::cout << i;
}
Run Code Online (Sandbox Code Playgroud)
我使用它吗?
是否真的有必要传递一些随机的int?
如果是这样,为什么呢?是因为模板的魔力是有限的,我实际上必须将int传递给函数服用int OR是出于某种目的设计的吗?(例如,强迫用户不要忘记函数声明的样子如何?)
我使用vs2012
我对shared_ptr复制构造函数有些困惑.请考虑以下两行:
它是对shared_ptr对象的"常量"引用,它被传递给复制构造函数,以便初始化另一个shared_ptr对象.
复制构造函数也应该增加一个成员数据 - "引用计数器" - 它也在所有shared_ptr对象之间共享,因为它是一个引用某个整数的引用/指针,告诉每个shared_ptr对象它们中有多少仍然存在活.
但是,如果复制构造函数尝试增加引用计数成员数据,它是否"命中"引用传递的shared_ptr的常量?或者,复制构造函数是否在内部使用const_cast运算符临时删除参数的常量?
我想比较ListA [0]和ListB [0] ......等.
ListA = [itemA, itemB, itemC]
ListB = [true, false, true]
for item in ListA:
if ListB[item] == True:
print"I have this item"
Run Code Online (Sandbox Code Playgroud)
目前的问题是[item]不是数字,因此ListB [item]不起作用.如果我想做这样的事情,那么正确的方法是什么?
我使用 Visual C++ 2012 编写了以下用于解析命令行参数的代码。这些命令行参数具有传统的 GNU 样式(--option)。
void parseCmdLines(int argc, wchar_t* argv[]) {
for (auto i = 1; i < argc; ++i) {
std::wstring arg(argv[i]);
// I hope it can match the L"--config=../etc/my.conf"
std::wregex regex(L"--config=(+*)");
std::wsmatch match;
std::regex_match(arg, match, regex);
// TODO: ...
}
Run Code Online (Sandbox Code Playgroud)
不幸的是,当我运行这个程序时,我遇到了一个异常。异常的描述如下:
Microsoft C++ exception: std::regex_error at memory location 0x23F090.
Run Code Online (Sandbox Code Playgroud)
我怎么解决这个问题?
c++ ×8
c++11 ×5
arrays ×1
class ×1
hash ×1
hashmap ×1
inheritance ×1
list ×1
polymorphism ×1
python ×1
regex ×1
shared-ptr ×1
subclass ×1
templates ×1
vim ×1
visual-c++ ×1