K
key9
Hi all
I wrote:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class BaseNode
{
public:
void return_message(string );
};
void BaseNode::return_message(string str)
{
std::cout << str;
}
int main(int argc, char *argv[])
{
string a = "dasdasd";
BaseNode test;
test.return_message(a);
system("PAUSE");
return EXIT_SUCCESS;
}
// ok this can pass compile but when I want to separated code to .h files:
//******************* main.cpp
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#include "BaseNode.h
int main(int argc, char *argv[])
{
string a = "dasdasd";
BaseNode test;
test.return_message(a);
system("PAUSE");
return EXIT_SUCCESS;
}
//******************* basenode.h
#ifndef BASENODE_H_
#define BASENODE_H_
class BaseNode
{
public:
void return_message(string );
};
#endif //BASENODE_H_
//******************* basenode.cpp
#include <string>
#include <iostream>
using namespace std;
void BaseNode::return_message(string str)
{
std::cout << str;
}
//this can not pass compile : 5 D:\a\testclass\BaseNode.cpp `BaseNode' has
not been declared
this confuse exist on my other post on compile ,cause undefined reference to
foo::foo() but when I move foo's implement to .h file , error gone.
so how to organize a class's .h and .cpp file?
I wrote:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
class BaseNode
{
public:
void return_message(string );
};
void BaseNode::return_message(string str)
{
std::cout << str;
}
int main(int argc, char *argv[])
{
string a = "dasdasd";
BaseNode test;
test.return_message(a);
system("PAUSE");
return EXIT_SUCCESS;
}
// ok this can pass compile but when I want to separated code to .h files:
//******************* main.cpp
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
#include "BaseNode.h
int main(int argc, char *argv[])
{
string a = "dasdasd";
BaseNode test;
test.return_message(a);
system("PAUSE");
return EXIT_SUCCESS;
}
//******************* basenode.h
#ifndef BASENODE_H_
#define BASENODE_H_
class BaseNode
{
public:
void return_message(string );
};
#endif //BASENODE_H_
//******************* basenode.cpp
#include <string>
#include <iostream>
using namespace std;
void BaseNode::return_message(string str)
{
std::cout << str;
}
//this can not pass compile : 5 D:\a\testclass\BaseNode.cpp `BaseNode' has
not been declared
this confuse exist on my other post on compile ,cause undefined reference to
foo::foo() but when I move foo's implement to .h file , error gone.
so how to organize a class's .h and .cpp file?