<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>class attributes and methods | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/class-attributes-and-methods/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Wed, 28 Dec 2022 16:19:10 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.1.7</generator>
	<item>
		<title>Class Attributes &#038; Methods</title>
		<link>https://studentprojects.in/software-development/cpp/class-attributes-methods/</link>
					<comments>https://studentprojects.in/software-development/cpp/class-attributes-methods/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Mon, 16 Jan 2023 16:10:25 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[class attributes and methods]]></category>
		<category><![CDATA[defining insides the class]]></category>
		<category><![CDATA[defining inside the class]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10098</guid>

					<description><![CDATA[<p>Variables and functions that are defined inside a class are called class attributes and methods. They are often collectively referred to as the class. Consider the following illustration to comprehend what class attributes are Two members, eId and eName, are defined inside the Employee class, which is created. These two individuals are class characteristics since</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/class-attributes-methods/">Class Attributes & Methods</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<p>Variables and functions that are defined inside a class are called class attributes and methods. They are often collectively referred to as the class.</p>



<p>Consider the following illustration to comprehend what class attributes are</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;

class Employee
{
    int eID;
    string eName;
    public:
};


int main()
{
    Employee Harry;
}</code></pre>



<p>Two members, eId and eName, are defined inside the Employee class, which is created. These two individuals are class characteristics since they are variables. Harry is now specified as an object in the main. Harry can use the dot operator to retrieve these characteristics. But unless they are made public, Harry cannot access them.</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">class Employee
{
public:
    int eID;
    string eName;
};


int main()
{
    Employee Harry;
    Harry.eID = 5;
    Harry.eName = "Harry";
    cout &lt;&lt; "Employee having ID " &lt;&lt; Harry.eID &lt;&lt; " is " &lt;&lt; Harry.eName &lt;&lt; endl;
}</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">Employee having ID 5 is Harry</code></pre>



<p>Class methods are simply functions that have been specified in or are a part of a class. The same way that objects access attributes, so do the methods that belong to a class. There are two ways to define a function so that it is a member of a class.</p>



<h3>Defining inside the class</h3>



<p>An illustration of how to define functions inside of classes is</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">class Employee
{
public:
    int eID;
    string eName;

    void printName()
    {
        cout &lt;&lt; eName &lt;&lt; endl;
    }
};</code></pre>



<h3>Defining outside the class</h3>



<p>A function must be declared inside the class even though it can be defined outside of it. Later, we can define the function outside using the scope resolution operator (::). An illustration of how to define functions outside of classes is</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">class Employee
{
public:
    int eID;
    string eName;

    void printName();
};


void Employee::printName()
{
    cout &lt;&lt; eName &lt;&lt; endl;
}</code></pre><p>The post <a href="https://studentprojects.in/software-development/cpp/class-attributes-methods/">Class Attributes & Methods</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/class-attributes-methods/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
