User forums > Using Code::Blocks

Issue placing classes in seperate files

(1/2) > >>

newbieC:
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;
}
--- End code ---

bent.cpp

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

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

bent.h

--- Code: ---#ifndef BENT_H
#define BENT_H


class bent
{
    public:
        bent();
};

#endif // BENT_H
--- End code ---

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)) ===|

--- End code ---

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!


stahta01:
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.


newbieC:

--- Quote from: stahta01 on January 06, 2014, 02:18:36 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.


--- End quote ---

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!

newbieC:

--- Quote from: stahta01 on January 06, 2014, 02:18:36 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.



--- End quote ---

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.

stahta01:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version