如何编译使用shared_ptr的程序
How to compile the program which uses shared_ptr?
Client.h
#ifndef TEST_CLIENT_H_
#define TEST_CLIENT_H_
#include <memory>
class SimpleClient {
public:
virtual int GetProgress() const = 0;
virtual char* CutPrefix(char* data) = 0;
virtual ~SimpleClient() {}
};
std::shared_ptr<SimpleClient> CreateSimpleClient();
#endif // TEST_CLIENT_H_
客户端.cpp
#include "client.h"
namespace {
class SimpleClientImpl : public SimpleClient {
private:
int progress_counter_;
public:
SimpleClientImpl() : progress_counter_(0) {}
int GetProgress() const;
char* CutPrefix(char* data);
};
int SimpleClientImpl::GetProgress() const {
return progress_counter_;
}
char* SimpleClientImpl::CutPrefix(char* data) {
progress_counter_++;
return data + *reinterpret_cast<size_t*>(data) + sizeof(size_t);
}
} // namespace
std::shared_ptr<SimpleClient> CreateSimpleClient() {
return std::shared_ptr<SimpleClient>(new SimpleClientImpl);
}
我试图编译:g++-c客户端.cpp,得到以下错误
在客户端.cpp中包含的文件中:2:client.h:13:错误:在"~<™代币client.cpp:27:错误:在"~<™代币
我从各种帖子中了解到我应该与鹅库链接,但不知道如何使用它。
这是我使用的编译器版本:
g++-v使用内置规格。目标:x86_64-redhat-linux配置为:/configure--prefix=/usr/mandir=/usr/share/man--infodir=/usr/share/info--使用bugurl=http://bugzilla.redhat.com/bugzilla--enable bootstrap--enable shared--enable threads=posix--enable checking=release--with system zlib--enable-_cxa_atexit--disable libunvell exceptions--enable gnu unique object--enable languages=c,c++,objc,obj-c++,java,fortran,ada--启用java awt=gtk--禁用dssi--使用java home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre--启用libgcj multifile--启用java maintainer模式--使用ecj jar=/usr/share/java/eclipse-ecj.jar--禁用libjava multilib--使用ppl--使用cloog--使用tune=generic--使用arch_32=i686--构建=x86_64-redhat-linux螺纹型号:posixgcc版本4.4.5 20101112(Red Hat 4.4.5-2)(gcc)
有人能帮我吗。
对于这么旧的编译器,您可能应该在编译器标志中添加-std=c++0x,而不是-std=c++11。
- CLANG 编译器 说:变量"PTR"可能未初始化
- 在以唯一ptr为值的C++映射中,动态内存何时会被销毁
- 将 ptr 传递给 ptr 到 A 作为参数传递给 A 的函数是不好的做法吗?
- 为共享 ptr 向量实现复制 c'tor?
- 字符和整数中 **(ptr+1) 的值差异
- C++:在不中断共享的情况下通过引用传递共享 PTR?
- 如何将派生类从基 ptr 分配给 nlohmann::json
- 引用 std::shared:ptr 以避免引用计数
- 为什么我不能在不进行任何转换的情况下将浮点数放入任何类型的 ptr 中?
- 在调用函数时,ptr** 和 ptr*& 之间是否有区别,或者首选C++?
- 另一种类型的智能ptr,比如具有弱refs的unique_ptr
- 尝试打印出 *ptr++ 的值,以了解它是如何工作的
- 如何控制共享 ptr 引用计数?
- dopen():不以 root 身份运行时"failed to map segment from shared object"
- C++中的指针否定 (!ptr == NULL)
- 从const ptr*转换为ptr*时出现问题
- 无法使用 libtool 将 -shared 参数传递给 g++
- boost::shared_ptr和std::shared-ptr的同居
- 我可以用std::shared_ptr而不是boost::shared-ptr构建boost库吗
- shared-ptr-C++shared_ptr与unique_ptr用于资源管理