Samacheer Kalvi · 11th TN - English Medium · Computer Science · Page 259

• Ternary operator ( ?:)

Chapter 3: 11th Computer Science · Computer Science · EN medium

From your actual textbook ✓

What does your textbook say about • Ternary operator ( ?:)?

Operator Overloading Syntax ReturnType classname :: Operator Operator Symbol (argument list) \\ Function body } Keyword Operator to be overloaded . . Restrictions on Operator Overloading Following are some restrictions to be kept in mind while implementing operator overloading. . Precedence and Associativity of an operator cannot be changed. . No new operators can be created, only existing operators can be overloaded. . Cannot redefine the meaning of an operator’s procedure. You cannot change how integers are added.Only additional functions can be given to an operator . Overloaded operators cannot have default arguments. .

📖 Namma Kalvi 11th Computer Science Textbook English Medium · Page 259

Read from the source

Complete lesson

Operator Overloading Syntax ReturnType classname :: Operator Operator Symbol (argument list) \\ Function body } Keyword Operator to be overloaded . . Restrictions on Operator Overloading Following are some restrictions to be kept in mind while implementing operator overloading. .

Precedence and Associativity of an operator cannot be changed. . No new operators can be created, only existing operators can be overloaded. .

Cannot redefine the meaning of an operator’s procedure. You cannot change how integers are added.Only additional functions can be given to an operator . Overloaded operators cannot have default arguments. .

When binary operators are overloaded, the left hand object must be an object of the relevant class #include<iostream> using namespace std; class complex { int real,img; public: void read() cout<<"\nEnter the REAL PART : "; cin>>real; cout<<"\nEnter the IMAGINARY PART : "; cin>>img; complex operator +(complex c2) complex c3; c3.real=real+c2.real; c3.img=img+c2.img; return c3; void display() { cout<<real<<"+"<<img<<"i"; } }; int main() complex c1,c2,c3; int choice, cont; cout<<"\n\nEnter the First Complex Number"; c1.read(); cout<<"\n\nEnter the Second Complex Number"; c2.read(); c3=c1+c2; // binary + overloaded cout<<"\n\nSUM = "; c3.display(); return ; Output

Related topics

Want this shaped for your exam marks?

Get an AI answer grounded in your actual textbook — with the exact page reference.

Ask AI about this topic →