<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Class_implementation_file</id>
	<title>Class implementation file - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://debianws.lexgopc.com/wiki143/index.php?action=history&amp;feed=atom&amp;title=Class_implementation_file"/>
	<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Class_implementation_file&amp;action=history"/>
	<updated>2026-05-05T00:36:58Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>http://debianws.lexgopc.com/wiki143/index.php?title=Class_implementation_file&amp;diff=1210316&amp;oldid=prev</id>
		<title>imported&gt;Mazewaxie: formatting, replaced: ’ → &#039; (5)</title>
		<link rel="alternate" type="text/html" href="http://debianws.lexgopc.com/wiki143/index.php?title=Class_implementation_file&amp;diff=1210316&amp;oldid=prev"/>
		<updated>2023-12-30T21:38:23Z</updated>

		<summary type="html">&lt;p&gt;formatting, replaced: ’ → &amp;#039; (5)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;In [[object-oriented programming]], a &amp;#039;&amp;#039;&amp;#039;class implementation file&amp;#039;&amp;#039;&amp;#039; is often used to contain the implementation code for the [[Method (computer programming)|method(s)]] of a [[Class (computer programming)|class]]. Programming languages like C++ and Objective-C make use of these implementation files so as to separate the interface and implementation of these methods.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| author     = Alan Griffiths&lt;br /&gt;
| title      = Separating Interface and Implementation in C++&lt;br /&gt;
| publisher  = ACCU&lt;br /&gt;
| year       = 2005&lt;br /&gt;
| url        = http://accu.org/index.php/journals/269&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Motivation==&lt;br /&gt;
Using this structure, a [[class definition]] file containing the declaration of the class and its members is also created.  If the class definition has been included and the implementation file for its methods is available, the user can [[Instance (computer science)|instantiate]] an [[object (computer science)|object]] of the class.  The purpose of this structure is to keep the implementation code hidden, but allow the user to view the design.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| author = Alan Griffiths&lt;br /&gt;
| title      = Separating Interface and Implementation in C++&lt;br /&gt;
| publisher = ACCU&lt;br /&gt;
| year = 2005&lt;br /&gt;
| url        = http://accu.org/index.php/journals/269&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite book&lt;br /&gt;
| last = Neuberg&lt;br /&gt;
| first = Matt&lt;br /&gt;
| date = 26 May 2011&lt;br /&gt;
| title = Programming iOS 4&lt;br /&gt;
| publisher = O&amp;#039;Reilly Media, Inc.&lt;br /&gt;
| chapter = Chapter 4.3 Header File and Implementation File&lt;br /&gt;
| isbn = 978-1-4493-8843-0&lt;br /&gt;
| url-access = registration&lt;br /&gt;
| url = https://archive.org/details/programmingios40000neub&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Users make use of the public interface of an [[object (computer science)|object]] so as to make creating objects as simple as possible, ensuring that client code does not distract the user with unnecessary details of the class&amp;#039;s implementation.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| author = Alan Griffiths&lt;br /&gt;
| title      = Separating Interface and Implementation in C++&lt;br /&gt;
| publisher = ACCU&lt;br /&gt;
| year = 2005&lt;br /&gt;
| url        = http://accu.org/index.php/journals/269&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
This allows the user the information needed to use the class effectively, but prevents him or her from damaging the compiled code.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = C++ Dos and Don&amp;#039;ts&lt;br /&gt;
| publisher  = The Chromium Projects&lt;br /&gt;
| url        = https://www.chromium.org/developers/coding-style/cpp-dos-and-donts&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The structure of a class implementation file==&lt;br /&gt;
An implementation file is used in [[The C++ Programming Language|C++ programming]] when creating a [[class definition]] to split the interface from the implementation. The [[header file]] would declare all the [[C++ classes|member functions]] (methods) and [[C++ classes|data methods]] (fields) that the class has.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = Introduction to C++ Classes&lt;br /&gt;
| url        = http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| author = Alan Griffiths&lt;br /&gt;
| title      = Separating Interface and Implementation in C++&lt;br /&gt;
| publisher = ACCU&lt;br /&gt;
| year = 2005&lt;br /&gt;
| url        = http://accu.org/index.php/journals/269&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| author = Febil Chacko Thanikal&lt;br /&gt;
| title      = How to define a template class in a .h file and implement it in a .cpp file&lt;br /&gt;
| publisher = Code Project&lt;br /&gt;
| year = 2009&lt;br /&gt;
| url        = http://www.codeproject.com/Articles/48575/How-to-define-a-template-class-in-a-h-file-and-imp&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The implementation file will contain the actual definition or [[source code]] of the methods declared in the [[header file]].  This file can start with a header block, which provides comments that describe the purpose of the defined class and any details about the creation of the actual file, such as the author of the file and date the file was created.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = The implementation file in C++ Programming&lt;br /&gt;
| publisher = ITechTalk&lt;br /&gt;
| url        = http://www.itechtalk.com/thread1517.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
It can also include any libraries from the [[C++ Standard Library]] that will be used by any of the declared methods in the file. The &amp;#039;&amp;#039;&amp;#039;class implementation file&amp;#039;&amp;#039;&amp;#039; will usually have a line to include the associated header file (see examples below).&lt;br /&gt;
&lt;br /&gt;
===Example in C++===&lt;br /&gt;
An example would be having a class called &amp;lt;code&amp;gt;ExampleClass&amp;lt;/code&amp;gt;. The header file of this C++ file would be named &amp;quot;example_class.h&amp;quot; and the implementation file would be &amp;quot;example_class.cc&amp;quot;.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = Introduction to C++ Classes&lt;br /&gt;
| url        = http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite book&lt;br /&gt;
| last = Neuberg&lt;br /&gt;
| first = Matt&lt;br /&gt;
| date = 26 May 2011&lt;br /&gt;
| title = Programming iOS 4&lt;br /&gt;
| publisher = O&amp;#039;Reilly Media, Inc.&lt;br /&gt;
| chapter = Chapter 4.3 Header File and Implementation File&lt;br /&gt;
| isbn = 978-1-4493-8843-0&lt;br /&gt;
| url-access = registration&lt;br /&gt;
| url = https://archive.org/details/programmingios40000neub&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
An example of the structure of &amp;#039;&amp;#039;&amp;#039;example_class.cc&amp;#039;&amp;#039;&amp;#039; would look like this:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;example_class.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
ExampleClass::ExampleClass() = default;&lt;br /&gt;
&lt;br /&gt;
void ExampleClass::AddSomething(int k) {&lt;br /&gt;
   ...&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, the implementation for the functions has been omitted, but the functions must be declared in &amp;#039;&amp;#039;&amp;#039;example_class.h&amp;#039;&amp;#039;&amp;#039; like this:&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = Introduction to C++ Classes&lt;br /&gt;
| url        = http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
class ExampleClass {&lt;br /&gt;
 public:&lt;br /&gt;
  ExampleClass();  // Constructor.&lt;br /&gt;
  void AddSomething(int k);&lt;br /&gt;
&lt;br /&gt;
 private:&lt;br /&gt;
  std::string name_;                      &lt;br /&gt;
};&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Example in Objective-C===&lt;br /&gt;
Another example of how a class implementation file would be structured can be seen with [[Objective-C]], which is used in [[iOS]] programming.&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite book&lt;br /&gt;
| last = Neuberg&lt;br /&gt;
| first = Matt&lt;br /&gt;
| date = 26 May 2011&lt;br /&gt;
| title = Programming iOS 4&lt;br /&gt;
| publisher = O&amp;#039;Reilly Media, Inc.&lt;br /&gt;
| chapter = Chapter 4.3 Header File and Implementation File&lt;br /&gt;
| isbn = 978-1-4493-8843-0&lt;br /&gt;
| url-access = registration&lt;br /&gt;
| url = https://archive.org/details/programmingios40000neub&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
This example will use &amp;quot;ExampleClass&amp;quot;. A notable difference between C++ and [[Objective-C]] when making use of these implementation files is the extensions used at the end of the files. In C++ it will be &amp;#039;&amp;#039;&amp;#039;.cpp&amp;#039;&amp;#039;&amp;#039;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = Introduction to C++ Classes&lt;br /&gt;
| url        = http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
and in [[Objective-C]] it will be &amp;#039;&amp;#039;&amp;#039;.m&amp;#039;&amp;#039;&amp;#039;,&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite book&lt;br /&gt;
| last = Neuberg&lt;br /&gt;
| first = Matt&lt;br /&gt;
| date = 26 May 2011&lt;br /&gt;
| title = Programming iOS 4&lt;br /&gt;
| publisher = O&amp;#039;Reilly Media, Inc.&lt;br /&gt;
| chapter = Chapter 4.3 Header File and Implementation File&lt;br /&gt;
| isbn = 978-1-4493-8843-0&lt;br /&gt;
| url-access = registration&lt;br /&gt;
| url = https://archive.org/details/programmingios40000neub&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
but both will use the same &amp;#039;&amp;#039;&amp;#039;.h&amp;#039;&amp;#039;&amp;#039; extension for their [[Header file| header file(s)]]&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite web&lt;br /&gt;
| access-date = 2013-05-07&lt;br /&gt;
| title      = Introduction to C++ Classes&lt;br /&gt;
| url        = http://pages.cs.wisc.edu/~hasti/cs368/CppTutorial/NOTES/CLASSES-INTRO.html&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&amp;lt;ref&amp;gt;&lt;br /&gt;
{{cite book&lt;br /&gt;
| last = Neuberg&lt;br /&gt;
| first = Matt&lt;br /&gt;
| date = 26 May 2011&lt;br /&gt;
| title = Programming iOS 4&lt;br /&gt;
| publisher = O&amp;#039;Reilly Media, Inc.&lt;br /&gt;
| chapter = Chapter 4.3 Header File and Implementation File&lt;br /&gt;
| isbn = 978-1-4493-8843-0&lt;br /&gt;
| url-access = registration&lt;br /&gt;
| url = https://archive.org/details/programmingios40000neub&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;/ref&amp;gt;&lt;br /&gt;
as shown in the example below.&lt;br /&gt;
&lt;br /&gt;
This is an example of &amp;#039;&amp;#039;&amp;#039;ExampleClass.h&amp;#039;&amp;#039;&amp;#039; in [[Objective-C]]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
#import &amp;lt;UIKit/UIKit.h&amp;gt;&lt;br /&gt;
&lt;br /&gt;
@interface ExampleClass : NSObject {&lt;br /&gt;
    // instance variable declarations go here&lt;br /&gt;
}&lt;br /&gt;
- (NSString*) name;&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This is an example of the &amp;#039;&amp;#039;&amp;#039;class&amp;#039;s implementation file&amp;#039;&amp;#039;&amp;#039; &amp;#039;&amp;#039;&amp;#039;Exampleclass.m&amp;#039;&amp;#039;&amp;#039; in [[Objective-C]]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;objc&amp;quot;&amp;gt;&lt;br /&gt;
#import &amp;quot;ExampleClass.h&amp;quot;&lt;br /&gt;
&lt;br /&gt;
@implementation ExampleClass&lt;br /&gt;
- (NSString*) name {&lt;br /&gt;
    return @&amp;quot;…&amp;quot;;&lt;br /&gt;
}&lt;br /&gt;
@end&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
*[[C++ classes]]&lt;br /&gt;
*[[Header file]]&lt;br /&gt;
*[[Source code]]&lt;br /&gt;
*[[C++ Standard Library]]&lt;br /&gt;
*[[Objective-C]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
&lt;br /&gt;
==External links==&lt;br /&gt;
* [http://my.safaribooksonline.com/book/programming/iphone/9781449397302/objective-c-classes/_header_file_and_implementation_file Header File and Implementation File]&lt;br /&gt;
&lt;br /&gt;
{{DEFAULTSORT:Class Implementation File}}&lt;br /&gt;
[[Category:Class (computer programming)]]&lt;br /&gt;
[[Category:Object-oriented programming languages]]&lt;br /&gt;
[[Category:C++]]&lt;br /&gt;
[[Category:Articles with example Objective-C code]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Mazewaxie</name></author>
	</entry>
</feed>