<?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"
	>
<channel>
	<title>Comments on: 8.2 &#8212; Classes and class members</title>
	<atom:link href="http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/</link>
	<description></description>
	<pubDate>Wed, 20 Aug 2008 08:32:45 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.5.1</generator>
		<item>
		<title>By: Learn C++ - &#187; 8.1 &#8212; Welcome to object-oriented programming</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-14388</link>
		<dc:creator>Learn C++ - &#187; 8.1 &#8212; Welcome to object-oriented programming</dc:creator>
		<pubDate>Mon, 05 May 2008 01:53:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-14388</guid>
		<description>[...] 2007      Prev/Next Posts   &#171; 7.11 &#8212; Namespaces &#124; Home &#124; 8.2 &#8212; Classes and class members &#187;     Thursday, August 23rd, 2007 at 10:54 [...]</description>
		<content:encoded><![CDATA[<p>[...] 2007      Prev/Next Posts   &laquo; 7.11 &#8212; Namespaces | Home | 8.2 &#8212; Classes and class members &raquo;     Thursday, August 23rd, 2007 at 10:54 [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11186</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 08 Apr 2008 03:47:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11186</guid>
		<description>strncpy simply copies N character of a zero-terminated string into another string.  So the above line copies 25 characters from strName to m_strName.</description>
		<content:encoded><![CDATA[<p>strncpy simply copies N character of a zero-terminated string into another string.  So the above line copies 25 characters from strName to m_strName.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: ny</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11076</link>
		<dc:creator>ny</dc:creator>
		<pubDate>Sun, 06 Apr 2008 12:56:32 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11076</guid>
		<description>hi alex.. 

still i  am confusing about using strncpy.. 

following line in ur program how its work i still didnt understand 

strncpy(m_strName, strName, 25); 


kind regards</description>
		<content:encoded><![CDATA[<p>hi alex.. </p>
<p>still i  am confusing about using strncpy.. </p>
<p>following line in ur program how its work i still didnt understand </p>
<p>strncpy(m_strName, strName, 25); </p>
<p>kind regards</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11034</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Sat, 05 Apr 2008 17:17:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11034</guid>
		<description>The class itself does not have an address, because it is just a definition.

An object of the class does have an address, because it is an actual variable.  You can find the address by using the address-of (&#038;) operator:

&lt;pre&gt;
Foo cMyFoo; // declare a Foo object
cout &lt;&lt; &#038;cMyFoo &lt;&lt; endl; // print its address
&lt;/pre&gt;

Member functions also have an address, because you can set a pointer to them, and you can pass their address into a function:

&lt;pre&gt;
int (Foo::*ptr)() = &#038;Foo::GetValue;
&lt;/pre&gt;

ptr is a pointer to a member function of Foo that takes no parameters and returns an integer.  It is being set to the address of the Foo::GetValue() function.</description>
		<content:encoded><![CDATA[<p>The class itself does not have an address, because it is just a definition.</p>
<p>An object of the class does have an address, because it is an actual variable.  You can find the address by using the address-of (&#038;) operator:</p>
<pre>
Foo cMyFoo; // declare a Foo object
cout < < &#038;cMyFoo << endl; // print its address
</pre>
<p>Member functions also have an address, because you can set a pointer to them, and you can pass their address into a function:</p>
</pre>
<pre>
int (Foo::*ptr)() = &#038;Foo::GetValue;
</pre>
<p>ptr is a pointer to a member function of Foo that takes no parameters and returns an integer.  It is being set to the address of the Foo::GetValue() function.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: prabhakar</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11023</link>
		<dc:creator>prabhakar</dc:creator>
		<pubDate>Sat, 05 Apr 2008 12:49:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-11023</guid>
		<description>i have a very fundamental problem.
a 'class' is declared. it has one 'private data-member' and one 'public member-function'. 
 
an object (instance of the class) is created after the 'closing curly brackets and the semicolon'  of the class-declaration.
 
what is the address of the class ?
what is the address of the class-object ?
what is the address of the member-function ?
 
please enlighten me to keep up my tempo of persuing c++.
 
thanks 
prabhakar.</description>
		<content:encoded><![CDATA[<p>i have a very fundamental problem.<br />
a &#8216;class&#8217; is declared. it has one &#8216;private data-member&#8217; and one &#8216;public member-function&#8217;. </p>
<p>an object (instance of the class) is created after the &#8216;closing curly brackets and the semicolon&#8217;  of the class-declaration.</p>
<p>what is the address of the class ?<br />
what is the address of the class-object ?<br />
what is the address of the member-function ?</p>
<p>please enlighten me to keep up my tempo of persuing c++.</p>
<p>thanks<br />
prabhakar.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10933</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 04 Apr 2008 18:58:13 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10933</guid>
		<description>I see what you are trying to do.  Yeah, you can't assign struct variables in global space that way.  If you want to initialize your global struct, you have to do it like this:

&lt;pre&gt;
DateStruct sToday = { 10, 14, 2014 };
&lt;/pre&gt;</description>
		<content:encoded><![CDATA[<p>I see what you are trying to do.  Yeah, you can&#8217;t assign struct variables in global space that way.  If you want to initialize your global struct, you have to do it like this:</p>
<pre>
DateStruct sToday = { 10, 14, 2014 };
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: dano</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10923</link>
		<dc:creator>dano</dc:creator>
		<pubDate>Fri, 04 Apr 2008 16:27:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10923</guid>
		<description>This is the whole thing I'm trying...
&lt;pre&gt;
#include 

struct DateStruct
{
  int nMonth;
  int nDay;
  int nYear;
};

int myInt = 5;

DateStruct sToday;
//sToday.nMonth = 10; *will cause error here
//sToday.nDay = 14;
//sToday.nYear = 2014;

void SetDate(DateStruct &#38;sDate, int nMonth, int nDay, int nYear)
{
  sDate.nMonth = nMonth;
  sDate.nDay = nDay;
  sDate.nYear = nYear;
}

int main()
{
  using namespace std;

  DateStruct sToday;

  sToday.nMonth = 10; * works O.K. if I assign here.
  sToday.nDay = 14;
  sToday.nYear = 2014;

  SetDate(sToday, 4, 4, 2008);

  cout &lt;&lt; "Date values are: " &lt;&lt; sToday.nMonth &lt;&lt; "/" &lt;&lt; sToday.nDay &lt;&lt; "/" &lt;&lt; sToday.nYear &lt;&lt; endl;

  return(0);
}
&lt;/pre&gt;
If I comment out setting the global sToday members and use the ones in main()
it works O.K. but not vice versa. So.... you can assign a value to global variables
when they are declared but not members of a struct? (int myInt = 5;)
Unless I'm making a syntax mistake somewhere. Need grouping braces? {} ?</description>
		<content:encoded><![CDATA[<p>This is the whole thing I&#8217;m trying&#8230;</p>
<pre>
#include 

struct DateStruct
{
  int nMonth;
  int nDay;
  int nYear;
};

int myInt = 5;

DateStruct sToday;
//sToday.nMonth = 10; *will cause error here
//sToday.nDay = 14;
//sToday.nYear = 2014;

void SetDate(DateStruct &amp;sDate, int nMonth, int nDay, int nYear)
{
  sDate.nMonth = nMonth;
  sDate.nDay = nDay;
  sDate.nYear = nYear;
}

int main()
{
  using namespace std;

  DateStruct sToday;

  sToday.nMonth = 10; * works O.K. if I assign here.
  sToday.nDay = 14;
  sToday.nYear = 2014;

  SetDate(sToday, 4, 4, 2008);

  cout < < "Date values are: " << sToday.nMonth << "/" << sToday.nDay << "/" << sToday.nYear << endl;

  return(0);
}
</pre>
<p>If I comment out setting the global sToday members and use the ones in main()<br />
it works O.K. but not vice versa. So&#8230;. you can assign a value to global variables<br />
when they are declared but not members of a struct? (int myInt = 5;)<br />
Unless I&#8217;m making a syntax mistake somewhere. Need grouping braces? {} ?</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10889</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Fri, 04 Apr 2008 00:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10889</guid>
		<description>Hmm, that's an odd one.  Is the code that uses sToday inside a function, or is it floating in global space?  Declarations can be in global space, but code that executes instructions can not be.  I would put the following code:

&lt;pre&gt;
DateStruct sToday;

  sToday.nMonth = 10;
  sToday.nDay = 14;
  sToday.nYear = 2014;
&lt;/pre&gt;

inside your main() function and then see if it works.  I suspect it will.

Also, as far as the &#038; goes, that means we're passing a DateStruct by reference instead of by value.  This will allow SetDate to modify the actual sDate we pass in instead of just a copy.</description>
		<content:encoded><![CDATA[<p>Hmm, that&#8217;s an odd one.  Is the code that uses sToday inside a function, or is it floating in global space?  Declarations can be in global space, but code that executes instructions can not be.  I would put the following code:</p>
<pre>
DateStruct sToday;

  sToday.nMonth = 10;
  sToday.nDay = 14;
  sToday.nYear = 2014;
</pre>
<p>inside your main() function and then see if it works.  I suspect it will.</p>
<p>Also, as far as the &#038; goes, that means we&#8217;re passing a DateStruct by reference instead of by value.  This will allow SetDate to modify the actual sDate we pass in instead of just a copy.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: dano</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10856</link>
		<dc:creator>dano</dc:creator>
		<pubDate>Thu, 03 Apr 2008 19:48:52 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-10856</guid>
		<description>I get build errors the on beginning example when trying to initialize manually.
&lt;pre&gt;
struct DateStruct
{
  int nMonth;
  int nDay;
  int nYear;
};

DateStruct sToday;

  sToday.nMonth = 10; ---- Errors here.
  sToday.nDay = 14;
  sToday.nYear = 2014;

void SetDate(DateStruct &#038;sDate, int nMonth, int nDay, int nYear)...
&lt;/pre&gt;

The error is: "expected constructor, destructor, or type conversion before '.' token.

Also, not quite sure why the &#038; reference for the &#038;sDate in the SetDate function?
Is this so just passing the reference instead of whole structure when calling the
function?

Thank you for your help.

p.s. Love these lessons</description>
		<content:encoded><![CDATA[<p>I get build errors the on beginning example when trying to initialize manually.</p>
<pre>
struct DateStruct
{
  int nMonth;
  int nDay;
  int nYear;
};

DateStruct sToday;

  sToday.nMonth = 10; ---- Errors here.
  sToday.nDay = 14;
  sToday.nYear = 2014;

void SetDate(DateStruct &#038;sDate, int nMonth, int nDay, int nYear)...
</pre>
<p>The error is: &#8220;expected constructor, destructor, or type conversion before &#8216;.&#8217; token.</p>
<p>Also, not quite sure why the &#038; reference for the &#038;sDate in the SetDate function?<br />
Is this so just passing the reference instead of whole structure when calling the<br />
function?</p>
<p>Thank you for your help.</p>
<p>p.s. Love these lessons</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Alex</title>
		<link>http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-6034</link>
		<dc:creator>Alex</dc:creator>
		<pubDate>Tue, 15 Jan 2008 00:43:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.learncpp.com/cpp-tutorial/82-classes-and-class-members/#comment-6034</guid>
		<description>It's possible to declare stuff after the end of main() -- for example, other variables, functions, etc...  The compiler treats that ; as a blank statement, which compiles to nothing.  So it's essentially ignored.  There's no reason for that ; to be there (it was a typo), but it doesn't hurt either.  (As a note to future readers, I removed the extraneous semicolon).</description>
		<content:encoded><![CDATA[<p>It&#8217;s possible to declare stuff after the end of main() &#8212; for example, other variables, functions, etc&#8230;  The compiler treats that ; as a blank statement, which compiles to nothing.  So it&#8217;s essentially ignored.  There&#8217;s no reason for that ; to be there (it was a typo), but it doesn&#8217;t hurt either.  (As a note to future readers, I removed the extraneous semicolon).</p>
]]></content:encoded>
	</item>
</channel>
</rss>
