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.

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|

It can't find this file, so it can't compile and link. You need to add that file to the project in Code Blocks. Right click on the project and click "Add Files", then maneuver to the project and select it. You might have to select the configuration too. Code Blocks will guide you. Then clean the project and build it and see if it works.

It can't find this file, so it can't compile and link. You need to add that file to the project in Code Blocks. Right click on the project and click "Add Files", then maneuver to the project and select it. You might have to select the configuration too. Code Blocks will guide you. Then clean the project and build it and see if it works.

Did this, it didn't work.

I opened the file, right clicked it and went to click Add file to current project, but all it said was Remove file from project. It is already in the project, but it still doesn't work, I just get the same errors.

Worked fine for me. Attached is a zipped file. Unzip and open the cbp file with Code Blocks and see if it works for you.

Worked fine for me. Attached is a zipped file. Unzip and open the cbp file with Code Blocks and see if it works for you.

Ah that works, it appears that the files were not in the correct directory of the one I made. Thanks :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.