<?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>default parameter | Student Projects</title>
	<atom:link href="https://studentprojects.in/tag/default-parameter/feed/" rel="self" type="application/rss+xml" />
	<link>https://studentprojects.in</link>
	<description>Microcontroller projects, Circuit Diagrams, Project Ideas</description>
	<lastBuildDate>Wed, 01 Feb 2023 09:28:17 +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>C++ Class Templates -Part-II</title>
		<link>https://studentprojects.in/software-development/cpp/c-class-templates-part-ii/</link>
					<comments>https://studentprojects.in/software-development/cpp/c-class-templates-part-ii/#respond</comments>
		
		<dc:creator><![CDATA[Shubhajna Rai]]></dc:creator>
		<pubDate>Sat, 04 Feb 2023 11:25:00 +0000</pubDate>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ class template]]></category>
		<category><![CDATA[default parameter]]></category>
		<guid isPermaLink="false">https://studentprojects.in/?p=10140</guid>

					<description><![CDATA[<p>C. Default Parameter Class templates can have default parameters, which means that you can specify a default data type for the template. If no argument is provided for the template, the default data type will be used. This allows for greater flexibility in using the template, as you can create a general-purpose template that can</p>
<p>The post <a href="https://studentprojects.in/software-development/cpp/c-class-templates-part-ii/">C++ Class Templates -Part-II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></description>
										<content:encoded><![CDATA[<h4>C. Default Parameter</h4>



<p>Class templates can have default parameters, which means that you can specify a default data type for the template. If no argument is provided for the template, the default data type will be used. This allows for greater flexibility in using the template, as you can create a general-purpose template that can handle multiple data types while also having a default behavior. The syntax for making a parameter have a default data type is &#8220;template &lt;typename T = defaultType&gt;&#8221;.</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">#include &lt;iostream&gt;
using namespace std;
 
template &lt;class T1 = int, class T2 = float, class T3 = char&gt;
class myClass
{
public:
    T1 data1;
    T2 data2;
    T3 data3;
 
    myClass(T1 a, T2 b, T3 c)
    {
        data1 = a;
        data2 = b;
        data3 = c;
    }
    void display()
    {
        cout &lt;&lt; "The value of a is " &lt;&lt; data1 &lt;&lt; endl;
        cout &lt;&lt; "The value of b is " &lt;&lt; data2 &lt;&lt; endl;
        cout &lt;&lt; "The value of c is " &lt;&lt; data3 &lt;&lt; endl;
    }
};
 
int main()
{
    myClass&lt;&gt; obj1(1, 4.3, 'C');
    obj1.display();
}</code></pre>



<p>Output:</p>



<pre class="wp-block-code"><code lang="cpp" class="language-cpp">The value of a is 1
The value of b is 4.3
The value of c is C</code></pre>



<p>An integer, a float, and a character are the template&#8217;s default definitions for its parameters. Now, if the programmer wants to alter the data types, they must be specifically mentioned and the object defined as in the preceding examples.</p><p>The post <a href="https://studentprojects.in/software-development/cpp/c-class-templates-part-ii/">C++ Class Templates -Part-II</a> first appeared on <a href="https://studentprojects.in">Student Projects</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://studentprojects.in/software-development/cpp/c-class-templates-part-ii/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
