我已经开始尝试C++ 11标准,我发现这个问题描述了如何从同一个类中的另一个ctor调用你的ctor以避免使用init方法等.现在我正在使用看起来像这样的代码尝试相同的事情:
HPP:
class Tokenizer
{
public:
Tokenizer();
Tokenizer(std::stringstream *lines);
virtual ~Tokenizer() {};
private:
std::stringstream *lines;
};
Run Code Online (Sandbox Code Playgroud)
CPP:
Tokenizer::Tokenizer()
: expected('=')
{
}
Tokenizer::Tokenizer(std::stringstream *lines)
: Tokenizer(),
lines(lines)
{
}
Run Code Online (Sandbox Code Playgroud)
但是这给了我错误:
In constructor ‘config::Tokenizer::Tokenizer(std::stringstream*)’:
/path/Tokenizer.cpp:14:20: error: mem-initializer for ‘config::Tokenizer::lines’ follows constructor delegation
我已经尝试先移动Tokenizer()部分,然后在列表中移动,但这并没有帮助.
这背后的原因是什么,我应该如何解决?我尝试lines(lines)
用this->lines = lines;
相反的方式移动到身体,它工作正常.但我真的希望能够使用初始化列表.
提前致谢!
是否有一些"好"的方法来检查传递给宏的变量是否是一个指针?例如
#define IS_PTR(x) something
int a;
#if IS_PTR(a)
printf("a pointer we have\n");
#else
printf("not a pointer we have\n");
#endif
Run Code Online (Sandbox Code Playgroud)
这个想法是,这不是运行时而是编译时,如下所示:我们根据变量是否为指针得到不同的代码.所以我希望IS_PTR()以某种方式评估某种常量表达式.我是怎么回事这个想法的?
我正在尝试学习gtkmm,并决定暂时尝试gtkmm 2.4,因为看起来很难让3.0在Debian上工作.无论如何,我正在尝试的例子是:http://developer.gnome.org/gtkmm-tutorial/2.24/sec-helloworld.html.en.它编译得很好,并且运行正常,但是当我关闭它时,valgrind会报告很多泄漏,这与此类似(点击按钮一次后):
==4254== Memcheck, a memory error detector
==4254== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==4254== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info
==4254== Command: ./bin/jmb
==4254==
Hello World
==4254==
==4254== HEAP SUMMARY:
==4254== in use at exit: 942,940 bytes in 7,968 blocks
==4254== total heap usage: 14,191 allocs, 6,223 frees, 3,272,961 bytes allocated
==4254==
==4254== LEAK SUMMARY:
==4254== definitely lost: 2,620 bytes in 6 blocks
==4254== indirectly …
Run Code Online (Sandbox Code Playgroud) 我正在摆弄c ++中的一些代码,由于某种原因我不想工作,我把它缩小到这种情况:
#include <thread>
#include <atomic>
#include <chrono>
#include <mutex>
#include <iostream>
using namespace std;
void test()
{
timed_mutex m;
m.lock();
std::cout << "Can i have the lock? " << m.try_lock() << std::endl;
std::cout << "in test(), should block for 10 seconds" << std::endl;
bool got_lock = m.try_lock_for(std::chrono::seconds(10));
std::cout << "Now i've blocked, got the lock: " << got_lock << std::endl;
m.unlock();
}
int main()
{
thread t = thread(&test);
t.join();
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
问题是test()根本不会阻塞,即使try_lock
返回false.有没有我忽略的东西,或者这是gcc中的一个错误,或者我应该去哪里找出什么是错的?感谢任何建议和帮助!
我编译这个小程序是这样的:g++ -pthread …
当我编译以下程序时(我从C++ 中的 64 位 ntohl()获得的所有定义的代码?这似乎很合理):
\n\n#include <stdint.h>\n#if defined(__linux__)\n#include <endian.h> //htobe64,be64toh\n#include <arpa/inet.h> //ntohs, ntohl, htonl, htons\n#elif defined(__FreeBSD__) || defined(__NetBSD__)\n#include <sys/endian.h>\n#elif defined(__OpenBSD__)\n#include <sys/types.h>\n#define be16toh(x) betoh16(x)\n#define be32toh(x) betoh32(x)\n#define be64toh(x) betoh64(x)\n#endif\n\nint main()\n{\n int64_t i = 0x1212121234343434;\n int64_t j = be64toh(i);\n return 0;\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n使用以下命令编译它时出现链接错误(我正在运行 linux):
\n\ngcc -std=c99 endian_test.c -o endian\n
Run Code Online (Sandbox Code Playgroud)\n\n我收到的错误是:
\n\nuser@host ~/src/c $ gcc -std=c99 derp.c \nendian_test.c: In function \xe2\x80\x98main\xe2\x80\x99:\nendian_test.c:17:2: warning: implicit declaration of function \xe2\x80\x98be64toh\xe2\x80\x99 [-Wimplicit-function-declaration]\n int64_t j = be64toh(i);\n ^\n/tmp/ccYonfH4.o: In function `main\':\nendian_test.c:(.text+0x23): undefined reference to …
Run Code Online (Sandbox Code Playgroud) 我有一个SECRET_KEY,如何使用python反编译用户密码?我假设加密方法是sha1.谢谢.
我有以下片段的Rust:
pub fn scope(&mut self) -> &mut HashMap<String, Type> {
let idx = self.vars.len() - 1;
&mut self.vars[idx]
}
Run Code Online (Sandbox Code Playgroud)
我已经意识到我有一些上下文,我想在函数的非可变版本中使用此函数,例如:
pub fn scope(&self) -> &HashMap<String, Type> {
let idx = self.vars.len() - 1;
&self.vars[idx]
}
Run Code Online (Sandbox Code Playgroud)
mut
两个功能之间只删除了3 秒.我可以以某种方式将这些变成一个函数,根据可变性来推导我返回的引用的可变性self
吗?是否有一些我可以使用或类似的特征?