我试图使用std :: unique_ptrs以异常安全的方式管理Windows HANDLE.
首先我试过:
struct HandleDeleter
{
void operator()( HANDLE handle )
{
if( handle )
{
FindVolumeClose( handle )
}
}
}
typedef std::unique_ptr< HANDLE, HandleDeleter > unique_vol_handle_t;
Run Code Online (Sandbox Code Playgroud)
稍后在我的代码中尝试使用它时:
unique_vol_handle_t volH( FindFirstVolumeW( buffer, MAX_GUID_PATH ) );
我从Visual Studio 2012RC收到以下错误:
1> error C2664: 'std::unique_ptr<_Ty,_Dx>::unique_ptr(std::nullptr_t) throw()' : cannot convert parameter 1 from 'HANDLE' to 'std::nullptr_t'
1> with
1> [
1> _Ty=HANDLE,
1> _Dx=VolumeHandleDeleter
1> ]
1> nullptr can only be converted to pointer or handle types
Run Code Online (Sandbox Code Playgroud)
引用上面的volH声明行.
搜索了一段时间后,我发现了一篇博文,基本上说,添加: …
我正在尝试使用Cmake,并开始在网站上找到一个简单的教程.这里的c ++代码尽可能简单:
#include <iostream>
int main(int argc, char *argv[])
{
std::cout << "Hello, World!" << std::endl;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
Cmake文件是:
cmake_minimum_required (VERSION 2.6)
project (Tutorial)
add_executable(Tutorial main.cpp)
Run Code Online (Sandbox Code Playgroud)
我使用cmake-gui生成Visual Studio C++解决方案和项目文件.我能够构建项目,但是当我尝试运行项目时,我得到一个提示,说明ZERO_CHECK项目已过期,并询问我是否要重建它.当我选择"是"时,我收到一条错误,指出:"无法启动程序..路径../调试/ ALL_BUILD系统找不到指定的文件".我做了很多搜索,但无法找到任何有类似错误的人.有没有人遇到过这样的事情?
我在一个全部是Subversion的商店里使用git.当我查看使用的回购时
git svn clone -s --preserve-empty-dirs https://<subversion-server>/svn/<repo> <folder-name>
克隆过程开始时似乎都很好,但在这个过程中的某个时刻,git失败了
Failed to strip path '<path-to-some-file>' ((?^:^trunk(/|$)))
任何人都知道什么是错的或如何解决这个问题?
嗯......我以为我理解正则表达式,我认为我理解迭代器,但C++ 11的正则表达式实现让我感到困惑......
我不明白的一个领域:阅读有关正则表达式令牌迭代器的内容,我遇到了以下示例代码:
#include <fstream>
#include <iostream>
#include <algorithm>
#include <iterator>
#include <regex>
int main()
{
std::string text = "Quick brown fox.";
// tokenization (non-matched fragments)
// Note that regex is matched only two times: when the third value is obtained
// the iterator is a suffix iterator.
std::regex ws_re("\\s+"); // whitespace
std::copy( std::sregex_token_iterator(text.begin(), text.end(), ws_re, -1),
std::sregex_token_iterator(),
std::ostream_iterator<std::string>(std::cout, "\n"));
...
}
Run Code Online (Sandbox Code Playgroud)
我不明白以下输出如何:
Quick
brown
fox.
Run Code Online (Sandbox Code Playgroud)
正在由上面的std :: copy()函数创建.我看不到循环,所以我对迭代的发生方式感到困惑.换句话说,如何生成多行输出?
我试图了解如何在Rust中实现一般特征.
虽然我已经看过很多例子,但这些例子与特定用途(例如基因组变异器)过于紧密联系,因此我能够在Rust开发过程中理解这一点.
相反,这是一个基于相当普遍的东西的简单示例 - 递增:
trait Incrementable {
fn post_inc(&mut self) -> Self;
fn post_inc_by(&mut self, n: usize) -> Self;
}
impl Incrementable for usize {
fn post_inc(&mut self) -> Self {
let tmp = *self;
*self += 1;
tmp
}
//"Overload" for full generalizability
fn post_inc_by(&mut self, n: usize) -> Self {
let tmp = *self;
*self += n;
tmp
}
}
fn main() {
let mut result = 0;
assert!(result.post_inc() == 0);
assert!(result == 1);
assert!(result.post_inc_by(3) …Run Code Online (Sandbox Code Playgroud) 该锈语言文档说,有关文档的意见(重点煤矿)以下内容:
文档注释使用
///而不是//[...]还有另一种文档注释样式//!,用于评论包含项目(例如板条箱,模块或函数),而不是后面的项目.
只是为了混淆事物,文档提供了一个使用///格式来记录函数的示例(通过链接可见,但在上面的省略号中省略).
我之前看到过这两种风格的同义词 - 在Rust中它们之间有区别吗?我在这里和互联网上的搜索没有任何结果.
当使用std :: vector的fill构造函数(任一形式)和C++ 11的类成员初始化功能时,以下代码无法编译(在clang/llvm 3.6下):
#include <vector>
class Foo
{
std::vector<char> buf_(10); //compiler error!
std::vector<std::vector<char>> buf2_(10, std::vector<char>(20)); //compiler error!
public:
void Bar();
};
void Foo::Bar()
{
std::vector<char> buf3_(10); //OK
std::vector<std::vector<char>> buf4_(10, std::vector<char>(20)); //OK
}
Run Code Online (Sandbox Code Playgroud)
我已经搜索了有关向量填充构造函数和类成员初始化的问题,但是已经空了.知道我错过了什么吗?
c++ ×3
c++11 ×3
rust ×2
cmake ×1
constructor ×1
copy ×1
git ×1
git-svn ×1
key-bindings ×1
macos ×1
regex ×1
sublimetext ×1
sublimetext2 ×1
sublimetext3 ×1
traits ×1
unique-ptr ×1
visual-c++ ×1