-1
出於某種原因,我的main.cpp不識別鏈接,它通過link.h文件包含並在link.cpp中定義。是否有可能makefile沒有正確地鏈接它們,否則afaik我應該在link.cpp和main.cpp中包含link.h,並且都可以將Link識別爲一個類。C++未知類型錯誤
的main.cpp
#include <iostream>
#include <link.h>
int main (int argc, const char * argv[]) {
int i = 10;
while(i >= 0) {
i--;
}
Link test = new Link();
std::cout << "Hello, World!2\n";
return 42;
}
link.h
#ifndef LINK_H
#define LINK_H
#include <string>
using namespace std;
class Link {
private:
string * value;
Link * next;
public:
Link(Link * nextLink, string * stringValue);
~Link();
}
#endif
link.cpp
#include <link.h>
Link::Link(Link * nextLink, string * stringValue) {
this.next = nextLink;
this.value = stringValue;
}
Link::~Link() {
delete value;
}
Link * Link::getNext() {
return next;
}
string * Link::getString() {
return value;
}
void Link::printAll() {
if (next != NULL) {
cout << value << "\n" << next->printAll();
} else {
cout << value << "\n";
}
}
你是如何在你的makefile聯繫起來? –
您的鏈接類似乎缺少結束分號。 –