Ted*_*ley 1 c++ linux c-preprocessor
我正在编译我以前编译的代码时,我收到"TCPSocket.h:35:错误:预期','或'......'在数字常量之前".
35号线是 TCPSocket(int port, bool vOutput, const int DIRECTORY_SIZE);
从下面粘贴的类声明
using namespace std;
class TCPSocket
{
public:
#define SEND_BUFFER_LENGTH 80
#define DIRECTORY_SIZE 8192
struct sockaddr_in myAddress, clientAddress;
TCPSocket(int port, bool vOutput, const int DIRECTORY_SIZE);
void buildTCPSocket(int newPort);
void processMessage(char* bufferIn, int currentTCPSocket, int tcpSocket, bool verboseOutput);
int getSocket1();
int getSocket2();
Run Code Online (Sandbox Code Playgroud)
定义或构造函数定义是明显的错误吗?
编辑:好的,所以对于那些将来阅读多年的人来说,这里是更正的构造函数声明:
TCPSocket(int port, bool vOutput);
Run Code Online (Sandbox Code Playgroud)
然后,在构造函数定义中使用定义的DIRECTORY_SIZE.
你不能这样做:
TCPSocket(int port, bool vOutput, const int DIRECTORY_SIZE);
Run Code Online (Sandbox Code Playgroud)
因为这意味着
TCPSocket(int port, bool vOutput, const int 8192);
Run Code Online (Sandbox Code Playgroud)
这不是合法的语法.我想你的意思是:
TCPSocket(int port, bool vOutput, const int nSize = DIRECTORY_SIZE);
Run Code Online (Sandbox Code Playgroud)