Author Topic: Issue placing classes in seperate files  (Read 8778 times)

Offline newbieC

  • Single posting newcomer
  • *
  • Posts: 4
Issue placing classes in seperate files
« on: January 06, 2014, 12:07:17 am »
PREFACE
Newbie warning, please take it easy on me, I literally just picked up c++ a few days ago so any explanation you give you'll have to dumb it down to kindergarten level for me.

With that said, I'm obviously learning the very basic syntax of c++ and how things go together. I've generally had pretty good success just messing around doing my own thing and making very simple little programs. The first roadblock that hit me was separating classes into different files. I tried to write the most simple code to just test it, and it will not compile for me, even after hours of toying around with it. So I felt the need to get some advice from more seasoned coders, before I toss my sanity out the window. Now I'm using this guy's youtube video(s) as reference, he as a very good way of simplifying a lot of the concepts.

http://www.youtube.com/watch?v=NTip15BHVZc

That's the video that has separating classes into different files. I copied his code word for word, just changing variable names to my own, and while his compiles, mine does not. I would like to know why that is? I know he is using a different (older) version of codeblocks, but does that change how files are supposed to compile?

Anyway, here's the code:

main.cpp
Code
#include <iostream>
#include "bent.h"
using namespace std;

int main()
{
   bent a;
   return 0;
}

bent.cpp
Code
#include "bent.h"
#include <iostream>
using namespace std;

bent::bent()
{
   cout << "testing 123" << endl;
}

bent.h
Code
#ifndef BENT_H
#define BENT_H


class bent
{
    public:
        bent();
};

#endif // BENT_H

Here is the error that I get:

Code
||=== Build: Debug in verti (compiler: GNU GCC Compiler) ===|
c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)||undefined reference to `WinMain@16'|
||=== Build failed: 1 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

Before you ask, I did use console application option, not windows application.
Now what I'm looking for really is how to change my code to make this compile and run. I get all the basic concepts this is supposed to represent so I'm good with that, but maybe a brief description of why my code doesn't work would be great, and a newbie step by step guide on how to fix it.

Thank you for your time!



Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Issue placing classes in seperate files
« Reply #1 on: January 06, 2014, 02:18:36 am »
You DID NOT post your main function! I just saw the main function.

FYI: I suggest reading the rules! http://forums.codeblocks.org/index.php/topic,9996.0.html

Are all the files part of a CB Project? If not, fix that.

Post the Full re-build Compiler build log. http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Edit3: Why does the error have "main.c" in it? I suggest you double check the main function filename extension.


Tim S.


« Last Edit: January 06, 2014, 02:22:17 am by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline newbieC

  • Single posting newcomer
  • *
  • Posts: 4
Re: Issue placing classes in seperate files
« Reply #2 on: January 06, 2014, 02:51:12 am »
codeblocks.org/index.php/topic,9996.0.html]http://forums.codeblocks.org/index.php/topic,9996.0.html[/url]

Are all the files part of a CB Project? If not, fix that.


Dear Tim,

I went to the top left and clicked File --> New --> Class and went through all the options and at the end it asked me to add it to my current project and I clicked yes. Is there any other way to check if its part of my CB project? I figured that was enough!

Offline newbieC

  • Single posting newcomer
  • *
  • Posts: 4
Re: Issue placing classes in seperate files
« Reply #3 on: January 06, 2014, 02:57:50 am »

Post the Full re-build Compiler build log. http://wiki.codeblocks.org/index.php?title=FAQ-Compiling_%28errors%29#Q:_How_do_I_troubleshoot_a_compiler_problem.3F

Edit3: Why does the error have "main.c" in it? I suggest you double check the main function filename extension.



Here is the pictures of what I'm working with

http://i39.tinypic.com/20h1p9g.png

http://i40.tinypic.com/111449d.png

http://i43.tinypic.com/2cp3jvr.png

I don't know what you mean by "Full re-build compiler build log" I went to that wiki and I have thecompiler logging full command line enabled, and that's the error it posted.
as to the error "main.c", I have no idea, that's why im posting here to find out! Like I said in my original post I followed a tutorial video to a tea so I assume I named everything correctly.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Issue placing classes in seperate files
« Reply #4 on: January 06, 2014, 03:26:49 am »
See the tab called "Build Log" it should have the build log.

Edit: A Full Re-build means do a re-build instead of build.

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline newbieC

  • Single posting newcomer
  • *
  • Posts: 4
Re: Issue placing classes in seperate files
« Reply #5 on: January 06, 2014, 04:00:09 am »
See the tab called "Build Log" it should have the build log.

Edit: A Full Re-build means do a re-build instead of build.

Tim S.


wow! so all I did was hit "rebuild" and it worked! any reason why it needed to be rebuilt (no change in code at all) for it to work? Thank you so much btw!

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9694
Re: Issue placing classes in seperate files
« Reply #6 on: January 06, 2014, 09:03:43 am »
wow! so all I did was hit "rebuild" and it worked! any reason why it needed to be rebuilt (no change in code at all) for it to work?
An example: You copied the old object files which had a newer time stamp than the source code files.
Another one: You changed a compiler flag and didn't re-build so that this change become evident.
Compiler logging: Settings->Compiler & Debugger->tab "Other"->Compiler logging="Full command line"
C::B Manual: https://www.codeblocks.org/docs/main_codeblocks_en.html
C::B FAQ: https://wiki.codeblocks.org/index.php?title=FAQ