Tôi nhận được lỗi trình biên dịch kỳ lạ khi cố gắng biên dịch chương trình khách C++ UDP.lỗi trình biên dịch C++ "không được khai báo trong phạm vi này"
g++ -o client Udp.cpp ClientMain.c -I. -lpthread
In file included from ClientMain.c:1:0:
Udp.h: In destructor ‘CUdpMsg::~CUdpMsg()’:
Udp.h:103:43: error: ‘free’ was not declared in this scope
Udp.h: In member function ‘void CUdpMsg::Add(in_addr_t, const void*, size_t)’:
Udp.h:109:34: error: ‘malloc’ was not declared in this scope
Udp.h:109:41: error: ‘memcpy’ was not declared in this scope
ClientMain.c: In function ‘int main(int, char**)’:
ClientMain.c:28:57: error: ‘memcpy’ was not declared in this scope
ClientMain.c:29:61: error: ‘printf’ was not declared in this scope
ClientMain.c:30:17: error: ‘stdout’ was not declared in this scope
ClientMain.c:30:23: error: ‘fflush’ was not declared in this scope
ClientMain.c:34:68: error: ‘printf’ was not declared in this scope
ClientMain.c:35:17: error: ‘stdout’ was not declared in this scope
ClientMain.c:35:23: error: ‘fflush’ was not declared in this scope
ClientMain.c:37:30: error: ‘usleep’ was not declared in this scope
Tôi có thông báo sau ở đầu tệp cpp của tôi.
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <cstdlib>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <errno.h>
các chức năng như 'memcpy' phải được khai báo bằng chuỗi. Có ai có một đầu mối tại sao điều này đang xảy ra? Cảm ơn.
Bạn nói rằng bạn có các tệp đó bao gồm trong tệp * "cpp" * của bạn, nhưng các lỗi nằm trong 'ClientMain.c' (lưu ý' .c', không phải '.cpp')? –
Tôi nghĩ rằng bạn cần bao gồm một số tệp đó trong 'UDP.h' – Djole
là bạn chỉ định không gian tên std cho hàm này gọi là – triclosan