我通过使用'Serializer'类中的共享指针来获取错误。在std :: shared_ptr中新建之前的预期标识符<>
这里是我的具体错误:
client.h:28:52: error: expected identifier before new
std::shared_ptr<Serializer> serializerObj2(new Serializer);
^
client.h:28:52: error: expected , or .. before new
这里是我最小的代码:
std::shared_ptr<Serializer> serializerObj2(new Serializer);
这里是我的扩展代码:
#include "serializer.h"
#include<iostream>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<stdlib.h>
#include<thread>
#include<string>
#include<cstring>
#include<utility>
#include <boost/filesystem.hpp>
#include<memory>
namespace TCP
{
class Client
{
public:
void start();
private:
int networkSocket=socket(AF_INET,SOCK_STREAM,0);
std::shared_ptr<Serializer> serializerObj2(new Serializer);
std::shared_ptr<Serializer> serializerObj=std::make_shared<Serializer>();
bool checkConnection();
std::pair<bool,std::string>getFile();
void sendMessage();
void setMessage();
};
}//closes namespace `
这里是我的串行.h文件:
#ifndef D_SERIALIZER_H
#define D_SERIALIZER_H
#include<iostream>
#include<arpa/inet.h>
#include<string>
namespace TCP
{
class Serializer
{
public:
//sender
void addIntToStream(int);
void addStringToStream(std::string);
void addCharToStream(char);
std::pair<bool,const char*>getStream(size_t requestSize_);
void delStream(size_t deleteSize_);
//receiver
void addByteToStream(const char*,size_t);
std::pair<bool,int> retrieveIntFromStream();
std::pair<bool,char> retrieveCharFromStream();
std::pair<bool,std::string> retrieveStringFromStream(int);
Serializer()
{
_stream="";
_it=_stream.begin();
}
private:
std::string _stream;
std::string::iterator _it;
};
} //closes namespace
#endif
1)的最小的[MCVE]代表“重现错误所需的最小” 2),这是不是C – user463035818
请产生[MCVE]。一个超级小例子,[像这样](https://wandbox.org/permlink/Gk5ksZQMKrg6NbMn)编译得很好。 – AndyG
通过玩游戏和发布幻想代码而不是真实代码,你正在这里浪费大家的时间。然后在指出你的问题后编辑你的问题(可以在编辑历史中清楚看到)。我删除了我的答案,并对您的问题进行投票,并将其视为题外话。请不要浪费只试图帮助你的人的时间,通过发布幻想代码而不是真实代码。失败。 –