I have been working with eclipse for c++ and all was fine. I want to try visual studio.
I have opened new project:
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;
}
but I have build errors:
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 ==========
I cant understand why is that.. anyone can help?
Joachim's answer (in comments):
You forgot to add a ;
after you class definition. The compiler suggests it too.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.