Author Topic: Question about making a class  (Read 4110 times)

Offline c_weed

  • Single posting newcomer
  • *
  • Posts: 9
Question about making a class
« 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?

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7252
Re: Question about making a class
« Reply #1 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.

Offline c_weed

  • Single posting newcomer
  • *
  • Posts: 9
Re: Question about making a class
« Reply #2 on: October 20, 2010, 08:38:50 am »
Got it.  :)

Offline c_weed

  • Single posting newcomer
  • *
  • Posts: 9
Re: Question about making a class
« Reply #3 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?

Offline MortenMacFly

  • Administrator
  • Lives here!
  • *****
  • Posts: 9723
Re: Question about making a class
« Reply #4 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.
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