cpp 未定义对"class::method"的引用
cpp undefined reference to `class::method'
当我试图编译时
$gcc-lcrl try.cpp
/tmp/ccJs0k9m.o: In function `main':
try.cpp:(.text+0x2d): undefined reference to `getURL::fetch(char*, char*)'
collect2: ld returned 1 exit status
该方法将显示在标头和类主体中。到底出了什么问题?
try.cpp
#include <curl/curl.h>
#include <curl/easy.h>
#include "getURL.h"
int main(void) {
getURL my_getURL;
my_getURL.fetch("http://stackoverflow.com/", "file");
}
getURL.h
#ifndef _getURL
#define _getURL
class getURL {
public:
void fetch(char *url, char *filename);
};
#endif
getURL.cpp
#include <curl/curl.h>
#include <curl/easy.h>
#include <stdio.h>
class getURL {
private CURL *curl;
public getURL() {
//code
}
public void fetch(char *url, char *filename) {
//code
}
private size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
//code
}
public ~getURL() {
//code
}
} //end class
您没有使用正确的实现语法;是
getURL::getURL() {
//code
}
void getURL::fetch(char *url, char *filename) {
//code
}
size_t getURL::write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
//code
}
getURL::~getURL() {
//code
}
请注意,您不能在实现中重复class
部分(只需包含标头)。还要注意,实现中不允许有在声明中不可见的私有成员。。。这很不幸,但这就是语言的定义。
您只编译了一个源文件。
更改:
gcc -lcurl try.cpp
至:
gcc -lcurl try.cpp getURL.cpp
相关文章:
- 将对象数组的引用传递给函数
- 什么时候在C++中返回常量引用是个好主意
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- 何时在引用或唯一指针上使用移动语义
- 如何在c++中使用引用实现类似python的行为
- 编译C++时未定义的引用
- Ctypes wstring通过引用传递
- c++r值引用应用于函数指针
- 理解c++中的引用
- C++取消引用指针.为什么会发生变化
- 如何修复此错误:未定义对"距离(浮点数,浮点数,浮点数,浮点数,浮点数)"的引用
- 我的项目不会像"undefined reference to `grpc::g_core_codegen_interface'"那样使用未定义的引用错误进行编译
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- 强制转换为引用类型
- 引用一个已擦除类型(void*)的指针
- cpp 未定义对"class::method"的引用
- 错误:对class::method(主、头文件、源代码)的未定义引用
- 对class::method的未定义引用
- C 中的链接器错误:对 c "method"未定义的引用
- "non-virtual thunk to <method name>" ,引用自:Vtable <classname>for in <objectfile.o>