C UNWORKOWN类型错误

C++ unkown type error

本文关键字:错误 类型 UNWORKOWN      更新时间:2023-10-16

由于某种原因,我的main.cpp不识别通过link.h文件包含的类型链接,并在link.cpp中定义。Makefile是否可能无法正确链接它们,否则我应该在link.cpp和main.cpp中包括link.h。

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!2n";
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";
}
}

我建议您尝试使用double引号,而不是&lt;和>;使用这些指示,编译器将文件查找到系统默认值中,其中包括首先,而双引号会使它在您的当前目录中看起来,我认为您已经将其放在其中。

因此,无论您在哪里引用标题:

,您的代码都会更改为
#include "link.h"