当我编译此代码时,我收到以下错误:
email2.cpp:27:对`email_client :: payload_text'
的未定义引用email2.cpp:28:对`email_client :: payload_text'
的未定义引用email2.cpp:29:对`email_client :: payload_text'
的未定义引用email2.cpp:30:对`email_client :: payload_text'
的未定义引用email2.cpp:31:对`email_client :: payload_text'
的未定义引用/tmp/ccE0wEII.o:email2.cpp:32:更多未定义的引用 `email_client :: payload_text'按照collect2:错误:ld返回1 退出状态
我的声明签名符合我的定义,因此我不确定如何处理这些错误。请帮忙。
CPP
#include <curl/curl.h>
#include <cstdio>
#include <string>
#include "email.h"
char* cat_char(std::string first, const char* second) {
char* tmp = new char[first.size()];
strcpy(tmp, first.c_str());
strcat(tmp, second);
strcat(tmp, "\r\n");
return tmp;
}
char* cat_char(std::string first) {
char* tmp = new char[first.size()];
strcpy(tmp, first.c_str());
strcat(tmp, "\r\n");
return tmp;
}
email_client::email_client(message msg, std::string TO, std::string FROM):
m_to(TO.c_str()),
m_from(FROM.c_str())
{
payload_text[0] = cat_char("To: ", TO.c_str());
payload_text[1] = cat_char("From: ", m_from);
payload_text[2] = cat_char("Subject: ", msg.subject.c_str());
payload_text[3] = cat_char("", "\r\n");
payload_text[4] = cat_char(msg.body, "\r\n");
payload_text[5] = NULL;
};
头
#include <string>
#include <cstring>
#include <cstdio>
struct message{
std::string subject;
std::string body;
};
char* cat_char(std::string first, const char* second);
char* cat_char(std::string first);
class email_client{
const char* m_to;
const char* m_from;
static char* payload_text[];
public:
email_client(message msg, std::string TO, std::string FROM="test@stest.com");
};