我的c代码使用'memset'和'close'.我补充说:
#include <stdio.h>
#include <glib.h>
#include <stdlib.h>
Run Code Online (Sandbox Code Playgroud)
但我仍然得到这些警告:
main.c:259: warning: implicit declaration of function ‘memset’
main.c:259: warning: incompatible implicit declaration of built-in function ‘memset’
main.c:268: warning: implicit declaration of function ‘close’
main.c:259: warning: incompatible implicit declaration of built-in function ‘close’
Run Code Online (Sandbox Code Playgroud)
你能告诉我怎样才能解决这些警告?
谢谢.
enum类型是签名还是未签名?枚举的签名是否在C/C99/ANSI C/C++/C++ x/GNU C/GNU C99中有所不同?
谢谢
考虑以下程序:
#include <cstddef>
#include <cstdio>
void f(char const*&&) { std::puts("char const*&&"); } // (1)
void f(char const* const&) { std::puts("char const* const&"); } // (2)
template <std::size_t N>
void f(char const (&)[N]) { std::puts("char const(&)[N]"); } // (3)
int main()
{
const char data[] = "a";
f(data);
}
Run Code Online (Sandbox Code Playgroud)
哪个f应该叫?为什么?
三个编译器的最新发布版本不同意这个问题的答案:
在不同的C++ 0x草案中,重载决策规则是否发生了很大变化?或者,这两个编译器真的完全错了吗?哪个重载是根据最新的C++ 0x草案选择的正确重载?
我有一个继承自的类型enable_shared_from_this<type>,以及从这种类型继承的另一种类型.现在我不能使用shared_from_this方法,因为它返回基类型,并且在特定的派生类方法中我需要派生类型.从这个直接构造shared_ptr是否有效?
编辑:在一个相关的问题中,我如何从一个类型的左值移动shared_ptr<base>到一个类型shared_ptr<derived>?我使用dynamic_cast来验证它确实是正确的类型,但现在我似乎无法完成实际的移动.
以下代码工作正常
#include <functional>
using namespace std;
using namespace std::placeholders;
class A
{
int operator()( int i, int j ) { return i - j; }
};
A a;
auto aBind = bind( &A::operator(), ref(a), _2, _1 );
Run Code Online (Sandbox Code Playgroud)
事实并非如此
#include <functional>
using namespace std;
using namespace std::placeholders;
class A
{
int operator()( int i, int j ) { return i - j; }
int operator()( int i ) { return -i; }
};
A a;
auto aBind = bind( &A::operator(), ref(a), …Run Code Online (Sandbox Code Playgroud) 我正在C++ 0x中实现一个压缩垃圾收集器供我个人使用,我有一个问题.显然,收集器的机制取决于移动对象,我一直想知道如何根据指向它的智能指针类型来实现它.我一直在考虑指针类型本身的指针指针,或者,收集器维护一个指向每个对象的指针列表,以便可以修改它们,从而在访问时无需双重de-ref指针但在收集期间添加一些额外的开销和额外的内存开销.什么是最好的方式去这里?
编辑:我主要关心的是快速分配和访问.我并不关心特别有效的收藏或其他维护,因为这不是GC的目的.
buffer = new char[64];
buffer = std::make_shared<char>(char[64]); ???
Run Code Online (Sandbox Code Playgroud)
你可以使用make_shared<>()?为数组分配内存吗?
我可以: buffer = std::make_shared<char>( new char[64] );
但这仍然涉及呼唤新的,这是我的理解make_shared更安全,更有效.
请考虑三个功能.
std::string get_a_string()
{
return "hello";
}
std::string get_a_string1()
{
return std::string("hello");
}
std::string get_a_string2()
{
std::string str("hello");
return str;
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
我正在查看c ++中字符串中字符的转义序列,我注意到有一个问号的转义序列.谁能告诉我为什么会这样?这看起来有点奇怪,我无法弄清楚是什么?做一个字符串.谢谢.
如果在Ubuntu 12.04上使用Clang 3.2或GCC 4.7进行编译,则以下示例成功运行(即不挂起),但如果我使用VS11 Beta或VS2012 RC进行编译,则会挂起.
#include <iostream>
#include <string>
#include <thread>
#include "boost/thread/thread.hpp"
void SleepFor(int ms) {
std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}
template<typename T>
class ThreadTest {
public:
ThreadTest() : thread_([] { SleepFor(10); }) {}
~ThreadTest() {
std::cout << "About to join\t" << id() << '\n';
thread_.join();
std::cout << "Joined\t\t" << id() << '\n';
}
private:
std::string id() const { return typeid(decltype(thread_)).name(); }
T thread_;
};
int main() {
static ThreadTest<std::thread> std_test;
static ThreadTest<boost::thread> boost_test;
// SleepFor(100);
}
Run Code Online (Sandbox Code Playgroud)
问题似乎是,std::thread::join()如果在main …