我一直在使用eclipse for c ++,一切都很好。我想尝试Visual Studio。
我打开了一个新项目:
myTree.h:
#ifndef myTree_H_
#define myTree_H_
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
class Node {
std::string word;
public:
Node() {
word="TEST";
}
std::string getString() {
return word;
}
}
#endif /* myTree_H_ */
test.cpp:
#include <stdio.h>
#include <iostream>
#include "myTree.h"
int main() {
Node myNode;
std::cout << myNode.getString() << std::endl;
return 0;
}
但我有构建错误:
c++\tree2\test.cpp(6): error C2628: 'Node' followed by 'int' is illegal (did you forget a ';'?)
c++\tree2\test.cpp(6): error C3874: return type of 'main' should be 'int' instead of 'Node'
c++\tree2\test.cpp(11): error C2664: 'Node::Node(const Node &)' : cannot convert parameter 1 from 'int' to 'const Node &'
1> Reason: cannot convert from 'int' to 'const Node'
1> No constructor could take the source type, or constructor overload resolution was ambiguous
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我不明白为什么会这样。任何人都可以提供帮助吗?
约阿希姆的回答(在评论中):
您忘了;
在课后定义中添加一个。编译器也建议这样做。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句