So I'm having a problem which I'm sure there is an extremely obvious solution for, but I just can't seem to figure it out. Basically, when I try to do class definitions in my headers and implementation in my source files, I am getting an error saying that I am redefining my classes. Using Visual C++ 2010 Express.
Exact error: "error C2011: 'Node' : 'class' type redefinition"
Example code included below:
Node.h:
#ifndef NODE_H
#define NODE_H
#include <string>
class Node{
public:
Node();
Node* getLC();
Node* getRC();
private:
Node* leftChild;
Node* rightChild;
};
#endif
Node.cpp:
#include "Node.h"
#include <string>
using namespace std;
class Node{
Node::Node(){
leftChild = NULL;
rightChild = NULL;
}
Node* Node::getLC(){
return leftChild;
}
Node* Node::getRC(){
return rightChild;
}
}
class Node{
Node::Node(){
leftChild = NULL;
rightChild = NULL;
}
Node* Node::getLC(){
return leftChild;
}
Node* Node::getRC(){
return rightChild;
}
}
you declare the class twice in your code, the second time being in your .cpp file. In order to write the functions for your class you would do the following
Node::Node()
{
//...
}
void Node::FunctionName(Type Params)
{
//...
}
no class is required
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With