<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: 1.9 &#8212; Header files</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/19-header-files/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/19-header-files/</link>
	<description></description>
	<lastBuildDate>Thu, 02 Feb 2012 21:20:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Wayne Wilhelm</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96866</link>
		<dc:creator>Wayne Wilhelm</dc:creator>
		<pubDate>Sat, 21 Jan 2012 07:18:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96866</guid>
		<description>Guess I need to quit posting and just read on.  All will be explained in good time...  Sorry!</description>
		<content:encoded><![CDATA[<p>Guess I need to quit posting and just read on.  All will be explained in good time&#8230;  Sorry!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Wilhelm</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96865</link>
		<dc:creator>Wayne Wilhelm</dc:creator>
		<pubDate>Sat, 21 Jan 2012 07:16:12 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96865</guid>
		<description>I now understand.  The next page we go to (1.10) explained the &lt;PRE&gt;#ifndef&lt;/PRE&gt; term.  Essentially the entire header file is an IF statment.  Because the term MATH_H has to be unique, we ask &lt;PRE&gt;#ifndef&lt;/PRE&gt; if not defined then perform all of the statements after until the next &lt;PRE&gt;#endif&lt;/PRE&gt; end of if statment.</description>
		<content:encoded><![CDATA[<p>I now understand.  The next page we go to (1.10) explained the
<pre>#ifndef</pre>
<p> term.  Essentially the entire header file is an IF statment.  Because the term MATH_H has to be unique, we ask
<pre>#ifndef</pre>
<p> if not defined then perform all of the statements after until the next
<pre>#endif</pre>
<p> end of if statment.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Wilhelm</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96863</link>
		<dc:creator>Wayne Wilhelm</dc:creator>
		<pubDate>Sat, 21 Jan 2012 01:14:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96863</guid>
		<description>I see the next page, Section 1.10 has this to say:
To prevent this from happening, we use header guards, which are conditional compilation directives that take the following form:
&lt;PRE&gt;
#ifndef SOME_UNIQUE_NAME_HERE 
#define SOME_UNIQUE_NAME_HERE   

// your declarations here   

#endif 
&lt;/PRE&gt;

SO, the &quot;MATH_H&quot; is merely some unique name to ensure the particular header file is not included more than once. I still don&#039;t understand the 
&lt;PRE&gt;#ifndef&lt;/PRE part though.</description>
		<content:encoded><![CDATA[<p>I see the next page, Section 1.10 has this to say:<br />
To prevent this from happening, we use header guards, which are conditional compilation directives that take the following form:</p>
<pre>
#ifndef SOME_UNIQUE_NAME_HERE
#define SOME_UNIQUE_NAME_HERE   

// your declarations here   

#endif
</pre>
<p>SO, the &#8220;MATH_H&#8221; is merely some unique name to ensure the particular header file is not included more than once. I still don&#8217;t understand the </p>
<pre>#ifndef&lt;/PRE part though.</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wayne Wilhelm</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96862</link>
		<dc:creator>Wayne Wilhelm</dc:creator>
		<pubDate>Sat, 21 Jan 2012 00:47:57 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96862</guid>
		<description>The following source for 
main.cpp, add.cpp and add.h 
worked using Microsoft Visual C++ Express 2010

I still don&#039;t understand the first two lines in the add.h file.
&lt;PRE&gt;#ifndef MATH_H&lt;/PRE&gt;
and
&lt;PRE&gt;#define MATH_H&lt;/PRE&gt;

My first impression was &quot;ifndef&quot; was a typo of &quot;define&quot; with &quot;MATH_H&quot; being a derivative of &quot;math.h&quot;. Apparently I&#039;m wrong since it does in fact work. I just don&#039;t understand the where and how of those two lines substance.

&lt;PRE&gt;#define&lt;/PRE&gt; makes sense
&lt;PRE&gt;#ifndef&lt;/PRE&gt; I don&#039;t understand. It looks like &quot;define&quot; scrambled.

&lt;PRE&gt;MATH_H&lt;/PRE&gt; I don&#039;t understand. &quot;math.h&quot; would seem to make more sense. I surmise &quot;MATH_H&quot; is a Microsoft addon to the standard library though I would think that would require an include statement, not a define.</description>
		<content:encoded><![CDATA[<p>The following source for<br />
main.cpp, add.cpp and add.h<br />
worked using Microsoft Visual C++ Express 2010</p>
<p>I still don&#8217;t understand the first two lines in the add.h file.</p>
<pre>#ifndef MATH_H</pre>
<p>and</p>
<pre>#define MATH_H</pre>
<p>My first impression was &#8220;ifndef&#8221; was a typo of &#8220;define&#8221; with &#8220;MATH_H&#8221; being a derivative of &#8220;math.h&#8221;. Apparently I&#8217;m wrong since it does in fact work. I just don&#8217;t understand the where and how of those two lines substance.</p>
<pre>#define</pre>
<p> makes sense</p>
<pre>#ifndef</pre>
<p> I don&#8217;t understand. It looks like &#8220;define&#8221; scrambled.</p>
<pre>MATH_H</pre>
<p> I don&#8217;t understand. &#8220;math.h&#8221; would seem to make more sense. I surmise &#8220;MATH_H&#8221; is a Microsoft addon to the standard library though I would think that would require an include statement, not a define.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nisbahmumtaz</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96791</link>
		<dc:creator>nisbahmumtaz</dc:creator>
		<pubDate>Fri, 06 Jan 2012 12:37:11 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96791</guid>
		<description>What I did was change the content of &quot;add.h&quot; by adding:

{
return x + y;
}

This way, I didn&#039;t even need the add.cpp and it compiled just fine.
I think this is a compatibility error on behalf of Alex, since this guide was made for C++03 originally.</description>
		<content:encoded><![CDATA[<p>What I did was change the content of &#8220;add.h&#8221; by adding:</p>
<p>{<br />
return x + y;<br />
}</p>
<p>This way, I didn&#8217;t even need the add.cpp and it compiled just fine.<br />
I think this is a compatibility error on behalf of Alex, since this guide was made for C++03 originally.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Nitin</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96779</link>
		<dc:creator>Nitin</dc:creator>
		<pubDate>Mon, 02 Jan 2012 07:38:25 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96779</guid>
		<description>amazing i find this website to be very helpful</description>
		<content:encoded><![CDATA[<p>amazing i find this website to be very helpful</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: 1.8 — Programs with multiple files &#171; kickasscomputing</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96729</link>
		<dc:creator>1.8 — Programs with multiple files &#171; kickasscomputing</dc:creator>
		<pubDate>Fri, 23 Dec 2011 08:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96729</guid>
		<description>[...] Now, when the compiler is compiling main.cpp, it will know what add is. Using this method, we can give files access to functions that live in another file. However, as programs grow larger and larger, it becomes tedious to have to forward declare every function you use that lives in a different file. To solve that problem, the concept of header files was introduced. We discuss header files in the lesson on header files. [...]</description>
		<content:encoded><![CDATA[<p>[...] Now, when the compiler is compiling main.cpp, it will know what add is. Using this method, we can give files access to functions that live in another file. However, as programs grow larger and larger, it becomes tedious to have to forward declare every function you use that lives in a different file. To solve that problem, the concept of header files was introduced. We discuss header files in the lesson on header files. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Programs with multiple files &#124; 4sharesite</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96686</link>
		<dc:creator>Programs with multiple files &#124; 4sharesite</dc:creator>
		<pubDate>Sun, 18 Dec 2011 13:08:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96686</guid>
		<description>[...] Now, when the compiler is compiling main.cpp, it will know what add is. Using this method, we can give files access to functions that live in another file. However, as programs grow larger and larger, it becomes tedious to have to forward declare every function you use that lives in a different file. To solve that problem, the concept of header files was introduced. We discuss header files in the lesson on header files. [...]</description>
		<content:encoded><![CDATA[<p>[...] Now, when the compiler is compiling main.cpp, it will know what add is. Using this method, we can give files access to functions that live in another file. However, as programs grow larger and larger, it becomes tedious to have to forward declare every function you use that lives in a different file. To solve that problem, the concept of header files was introduced. We discuss header files in the lesson on header files. [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: mm</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-3/#comment-96577</link>
		<dc:creator>mm</dc:creator>
		<pubDate>Thu, 08 Dec 2011 15:55:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96577</guid>
		<description>Hi 
I tried  to use the add() function in a Class. 
But I got this error :
	error LNK2019: unresolved external symbol &quot;public: int __thiscall Class1::add(int,int)&quot; (?add@Class1@@QAEHHH@Z) referenced in function _main	
	error LNK1120: 1 unresolved externals

I am using Microsoft Visual Studio 2008. Created a win32 Console Application.


I have put the 3 files below. Main.cpp Class1.cpp and Class1.h 
There seems to be a problem Linking but I can not figure out why.
Thanks a lot for your help, greatly appreciate your help.

FILE: MAIN.cpp_____________________________________________

#include 
#include  
#include &quot;Class1.h&quot;
int main()
{   
	Class1 c;
	int res=c.add(3, 4);
    return 0;
}
_____________________________________________
FILE: Class1.cpp_____________________________________________
#include 

	class Class1
	{
	public:
		int add(int x, int y)
		{
			return x + y; 
		}
	};

_____________________________________________
FILE:Class1.h_____________________________________________
#ifndef CLASS1_H 
#define CLASS1_H  

	class Class1
	{
	public:
		int add(int x, int y); // function prototype  
	};

#endif</description>
		<content:encoded><![CDATA[<p>Hi<br />
I tried  to use the add() function in a Class.<br />
But I got this error :<br />
	error LNK2019: unresolved external symbol &#8220;public: int __thiscall Class1::add(int,int)&#8221; (?add@Class1@@QAEHHH@Z) referenced in function _main<br />
	error LNK1120: 1 unresolved externals</p>
<p>I am using Microsoft Visual Studio 2008. Created a win32 Console Application.</p>
<p>I have put the 3 files below. Main.cpp Class1.cpp and Class1.h<br />
There seems to be a problem Linking but I can not figure out why.<br />
Thanks a lot for your help, greatly appreciate your help.</p>
<p>FILE: MAIN.cpp_____________________________________________</p>
<p>#include<br />
#include<br />
#include &#8220;Class1.h&#8221;<br />
int main()<br />
{<br />
	Class1 c;<br />
	int res=c.add(3, 4);<br />
    return 0;<br />
}<br />
_____________________________________________<br />
FILE: Class1.cpp_____________________________________________<br />
#include </p>
<p>	class Class1<br />
	{<br />
	public:<br />
		int add(int x, int y)<br />
		{<br />
			return x + y;<br />
		}<br />
	};</p>
<p>_____________________________________________<br />
FILE:Class1.h_____________________________________________<br />
#ifndef CLASS1_H<br />
#define CLASS1_H  </p>
<p>	class Class1<br />
	{<br />
	public:<br />
		int add(int x, int y); // function prototype<br />
	};</p>
<p>#endif</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Parse text file for name value pair - Page 2</title>
		<link>http://www.learncpp.com/cpp-tutorial/19-header-files/comment-page-2/#comment-96557</link>
		<dc:creator>Parse text file for name value pair - Page 2</dc:creator>
		<pubDate>Tue, 06 Dec 2011 17:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/?p=32#comment-96557</guid>
		<description>[...] Thanks. Have been reading the cplusplus.com tutorial. Think there are a few other ones also. This is also a good one. http://www.learncpp.com/cpp-tutorial/19-header-files/ [...]</description>
		<content:encoded><![CDATA[<p>[...] Thanks. Have been reading the cplusplus.com tutorial. Think there are a few other ones also. This is also a good one. <a href="http://www.learncpp.com/cpp-tutorial/19-header-files/" rel="nofollow">http://www.learncpp.com/cpp-tutorial/19-header-files/</a> [...]</p>
]]></content:encoded>
	</item>
</channel>
</rss>

