Error while putting classes in separate files

+2 Bijay Das · April 14, 2015
I'm trying to put my classes in separate files but I'm getting an error. I don't know why, I've watched the 15th c++ video several times and I've done exactly same the way but I'm facing the same prob. Can anyone please help me with this?

Post a Reply


- page 1
Oldest  Newest  Rating
0 Dol Lod · April 14, 2015
You are putting your class and function prototypes in headers files, right? Then you include those header files  in the source files you wish to use. At least one cpp must implement all prototyped functions. You also need header guards for all header files to make sure they aren;t included more than once for each file they are loaded with. 

If you're using your own makefile, you have to list dependencies.

If you're using an IDE like Visual Studio,XCODE, simply look for warnings.

If you're using Eclipse, switch to a different IDE, ASAP. It will give you errors that are impossible to fix. 
0 Mahmoud Abdel Mon'em · April 14, 2015
I get an error also:
"undefined references to 'WinMain@16'

Dunno what it means really, I'm still beginner at C++, learning from Bucky's videos, I've done the exact same thing he did on his video to separate classes in another file, but I'm still getting that error. If anyone can help so please say. :)
+2 Yazer Cha · April 14, 2015
If you could put a sample of your code that would make it easier for us to determine what is wrong with your code.

I will try to help if you do that.
+1 Bijay Das · April 14, 2015
0 Dol Lod · April 14, 2015
Which IDE are you using? That could possibly be the issue. I think this is CodeBlocks. Using CodeBlocks has never worked well for me. I would not recommend it as an IDE. 

Try running with CLION,Visual Studio or Xcode instead. CodeBlocks rarely works for me. Additionally, all three of these IDES are good for debugging code or pointing out problems if they exist.

I went through your syntax and cannot find the issue. Everything is defined clearly with correct syntax. 
0 Yazer Cha · April 15, 2015
I honestly have no idea what is going wrong.  I tried it in XCODE and it worked just fine for me.  I would recommend you download an IDE other than codeblocks.
0 Brian Reed · April 15, 2015
Hello All:

I think code blocks will work well for anyone going through the tutorials here8-)
However, I too have had issues the first time I started adding a class to a project:(
Don't try too long looking for the answers on the net, I spent hours with no good luck:angry:

Bijay Das:

Not sure of errors your getting, but it usually has to do with how the classes are created the first time. I kept using the same main class for all my testing of code, then when it came time to add classes that's when I had problems

I would recommend you start a new project from scratch. This should a least keep everything properly referenced together and under the same roof, so to speak.

Check out the C++ post
Need Help on C++ Tutorial 15 and 42 dated March 26 and follow Faha Sharapov lead on the second page.

Mahmoud Abdel Mon'em:
 "undefined references to 'WinMain@16'  This was my issue too!

0 Bijay Das · April 15, 2015
First of all thank you everyone for your answers.
Bucky uses code::blocks and this program worked perfectly. And you guys are telling me change my IDE, I will, but which should I use(xcode / clion / Visual Studio), I am using 32 bit  Window 7 Home Premium, 3 GB RAM), core 2 duo processor? I saw the iTunes page in Wikipedia it says iTunes written in c++. Which IDE is used by the professionals? Do I need to purchase that? I live in Delhi, India. How much it will cost?
0 Anthony Tremaglio · April 15, 2015
Bijay, apparently this is some sort of issue with code::blocks.  There is a workaround but not a fix.

After you create a class in a separate file, you have to save your project, close the project and reopen the project.  If you do that before trying to run the program you won't get that error.

Hope this helps.
0 Dol Lod · April 15, 2015
If you are planning to distribute the application, I would use CLION b/c it will help you actually catch errors.

If you're planning on just having a personal copy, use visual studio since it is easy to work with. 



Used in many types of software including music players, video games, and many large scale applications.

Bucky Roberts Administrator