Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: c_weed on October 20, 2010, 12:06:47 am

Title: Question about making a class
Post by: c_weed on October 20, 2010, 12:06:47 am
Hello everyone,  :D

It was my understanding that the main file (main.cpp) includes the header file (MyClass.h) which includes the implementation file (MyClass.cpp)

main.cpp-->MyClass.h-->MyClass.cpp

So how come when I select new, class Code::Blocks gave me this
Code
#include LinkedList.h

#include "LinkedList.h"

LinkedList::LinkedList()
{
    //constructor
   
}

LinkedList::~LinkedList()
{
    //dtor
}

where the header file is included in the implementation file?
Title: Re: Question about making a class
Post by: Jenna on October 20, 2010, 12:11:02 am
Because your
[..] understanding that the main file (main.cpp) includes the header file (MyClass.h) which includes the implementation file (MyClass.cpp)

main.cpp-->MyClass.h-->MyClass.cpp
is wrong.
Title: Re: Question about making a class
Post by: c_weed on October 20, 2010, 08:38:50 am
Got it.  :)
Title: Re: Question about making a class
Post by: c_weed on October 26, 2010, 01:11:10 am
I thought I got it but didn't after all. I thought you were saying that the implementation file should include its header file, but I thought the main file included the implementation file.

main.cpp-->class.cpp-->class.h
how come this is wrong?

how does including the header from the main file work because doesn't the implementation (class.cpp) not get included?
Title: Re: Question about making a class
Post by: MortenMacFly on October 26, 2010, 07:00:32 am
how does including the header from the main file work because doesn't the implementation (class.cpp) not get included?
Sorry, but this is no longer within the scope of our forum and violates the forum rules therefore. Please grab yourself a C++ beginners book and read about the basics. Basically sections about how a compiler works, and what a linker does.

Topic locked.