Files: Header, Implementation, Test

  • Thread starter Thread starter Jammin_James
  • Start date Start date
  • Tags Tags
    files Test
AI Thread Summary
The discussion centers around understanding the structure and purpose of header and implementation files in programming, particularly in the context of a Data Structures class. The user expresses confusion about function declarations and definitions, specifically regarding a class named "Date." It is clarified that the class declaration in the header file includes a constructor, which shares the same name as the class. The syntax for defining the constructor in the implementation file is explained, highlighting that the declaration in the header file serves to inform other files about the class's existence and its methods. The importance of using header files for modular programming is emphasized, as they allow for the reuse of class definitions across different source files, similar to how standard libraries operate. This modular approach facilitates code organization and reusability in programming.
Jammin_James
Messages
49
Reaction score
0
Hey all!

I've been reading through my book trying to figure all this out for my Data Structures class and I'm typing this out while I take a break from reading the book.

I'm looking over the examples from class and my teacher has header, implementation and test files. There is no input from a user that I can see in these programs, which is where these test files come in. Also, I think I understand why people use header and imp files, but I'm having troubles understanding how aurguments are passed between them. I'm also having trouble with the declarations in header and implementation files.

IN HEADER:

class Date
{
Date(arguments)
}

IN IMPLEMENTATION FILE:

Date::Date(arguments)

Is my teacher making the function declaration twice?

I could link the code if you'd like because I really doubt any of this made sense, haha.
 
Technology news on Phys.org
Jammin_James said:
Hey all!

I've been reading through my book trying to figure all this out for my Data Structures class and I'm typing this out while I take a break from reading the book.

I'm looking over the examples from class and my teacher has header, implementation and test files. There is no input from a user that I can see in these programs, which is where these test files come in. Also, I think I understand why people use header and imp files, but I'm having troubles understanding how aurguments are passed between them. I'm also having trouble with the declarations in header and implementation files.

IN HEADER:

class Date
{
Date(arguments)
}

IN IMPLEMENTATION FILE:

Date::Date(arguments)

Is my teacher making the function declaration twice?

I could link the code if you'd like because I really doubt any of this made sense, haha.

Yeah putting the actual code is better than things out of context.


But you are missing the basics with this one.


The declaration is

class Date
{
Date(args);
myMethod(args);
}

That is the declaration. And the fact that the function and the class share the same name, means it is a special type of method: a constructor


Now you still need to define the function ( you can do it in the declaration, but let's keep it like your code ).

so in a cpp file you need to define it.

the syntax

Date::Date(args)
{
//some code
}

is the definition.

Data::myMethod(args)
{
// some code
}

and that defines my new method
 
Now let me explain your other issue.

If you are creating a simple program and you want to define a few classes for your program. You can do it with one file.

But the reason for header files is so you can create the declarations so that you can implement code in modules.

You build classes, such as your date class. And all you have to do is include the header file any source file, and that source file will see the definition of the Date class.

And when you build your program, you just need to make sure you have the definition source file, ( or object or library file.. ) and you have a Date class that can be reused over and over again.

That is how the standard libraries work. You get the header files and include them, and somewhere in library files are the definitions.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top