I just watched this tutorial:
http://www.youtube.com/watch?v=NTip15BHVZc
and tried it myself, but I could not get it to work, I get these errors:
||=== 15. Placing classes in separate files, Debug ===|
C:\Program Files (x86)\CodeBlocks\programs\tutorials\15. Placing classes in separate files\src\testClassFile.cpp|1|error: testClassFile.h: No such file or directory|
C:\Program Files (x86)\CodeBlocks\programs\tutorials\15. Placing classes in separate files\src\testClassFile.cpp|5|error: 'testClassFile' has not been declared|
C:\Program Files (x86)\CodeBlocks\programs\tutorials\15. Placing classes in separate files\src\testClassFile.cpp|5|error: ISO C++ forbids declaration of 'testClassFile' with no type|
C:\Program Files (x86)\CodeBlocks\programs\tutorials\15. Placing classes in separate files\src\testClassFile.cpp||In function 'int testClassFile()':|
C:\Program Files (x86)\CodeBlocks\programs\tutorials\15. Placing classes in separate files\src\testClassFile.cpp|8|warning: no return statement in function returning non-void|
||=== Build finished: 3 errors, 1 warnings ===|
Here is the code from each of the 3 files:
main.cpp:
#include <iostream>
#include "testClassFile.h" //include the header file
using namespace std;
int main()
{
testClassFile test;
return 0;
}
// To create a new file, go to file > new > class
// Name the class, deselect has destructor/virtual destructor, select header/implementation file shall be in the same folder
// Click yes etc.
// It creates a <class>.h and <class>.cpp file
// .h file - type all variables and function prototypes
// .cpp file - main code, function
// #include the required stuff in the .cpp file
include\testClassFile.h:
#ifndef TESTCLASSFILE_H
#define TESTCLASSFILE_H
class testClassFile
{
public:
testClassFile();
};
#endif // TESTCLASSFILE_H
src\testClassFile.cpp:
#include "testClassFile.h"
#include <iostream>
using namespace std;
testClassFile::testClassFile() //the first testClassFile = the class name, the second is the function name (this one is a constructor). x::y() means y is a member of class x
{
cout << "this is text in a constructor";
}
I am using Code::Blocks.
Thanks.