class Complex private double x y static int z public Complex-00360
This subjective question is related to the book/course vu cs201 Introduction to Programming. It can also be found in vu cs201 Mid Term Solved Past Paper No. 5.
Question 1: class Complex
{
private:
double x,y;
static int z;
public:
Complex(double = 0.0);
friend ostream& operator<<(ostream&, const Complex&);
static int doSomething( ) { z = 2 * y; return z; }
};
{
private:
double x,y;
static int z;
public:
Complex(double = 0.0);
friend ostream& operator<<(ostream&, const Complex&);
static int doSomething( ) { z = 2 * y; return z; }
};
a. What is wrong in the definition of member function doSomething().
b. What will be the effect of writing the friend function operator<<(…) in private part of the above class
Answer:
a) Static keyword because using static key word we are declaring a static member function doSomething(). Which can not use non static data members.
b) There will be no effect on friend function if we write it in private part. Friend function is a friend function and can use any private or public data member of the class. Where ever we declare it in class body.