Changes

Jump to: navigation, search

Assignment 2 (Release 0.3): Q & A

1,172 bytes added, 19:01, 11 November 2012
Q & A
== Q & A ==
'''Q:''' How to initialize constant data member variables of class ? <br>
'''A:''' As we know constant things in c++ can only be initialized.They cannot be assigned later. Also in c++ during class declaration we cannot initialize things.so the only way in which we can initialize constant data members of class is by using initialization list.following piece of code will explain it clearly:
<br>
<nowiki>#include <iostream> </nowiki>
<br>
using namespace std;
 
class test
<nowiki>{</nowiki>
<br>
private:
const int i;
public:
test(int f):i(f)
{
cout<<"i = "<<i<<endl;
}
<nowiki>};</nowiki>
<br>
int main()
{
const int k =9;
test t(k);
return 0;
}
<br>
'''Submitted by:''' Shajinth Pathmakulaseelan and Auquib Rasul, Team 2 <br><br>
 
'''Q:''' What is the use of this pointer? <br>
'''A:''' this pointer is passed as an implicit argument to member function of class. This pointer contains the address of invoking object i.e the object on which member function is called.this pointer is very useful during operator overloading. <br>
'''Submitted by:''' Shajinth Pathmakulaseelan and Auquib Rasul, Team 2 <br><br>
== Bug Reports ==

Navigation menu