हिंदी
Tamil Nadu Board of Secondary EducationHSC Science Class 11

Operator Overloading and Type Conversions

Advertisements

Topics

  • Introduction to Computers
    • Introduction to Computers
    • Generations of Computers
    • Sixth Generation Computing
    • Data and Information
    • Components of a Computer
    • Booting of Computer
  • Number Systems
  • Computer Organization
    • Introduction to Computer Organization
    • Basics of Microprocessors
    • Data Communication Between CPU and Memory
    • Types of Microprocessors
    • Memory Unit (Memory Devices)
    • Secondary Memory Unit (Secondary Storage Devices)
    • Ports and Interfaces
  • Theoretical Concepts of Operating System
    • Introduction to Software
    • Introduction To Operating System (OS)
    • Types of Operating System - Interactive (Gui Based), Time Sharing, Real Time and Distributed
    • Key Features of the Operating System
    • Prominent Operating Systems
  • Working with Windows Operating System
    • Introduction To Operating System (OS)
    • Introduction to Windows Operating System
    • Various Versions of Windows
    • Handling the Mouse
    • Windows Desktop
    • The Window
    • Application Window
    • Document Window
    • Elements of a Window
    • Taskbar
    • Managing Files and Folders
    • Creating Shortcuts on the Desktop
    • Shutting Down or Logging off a Computer
  • Specification and Abstraction
    • Algorithms
    • Algorithmic Problems
    • Building Blocks of Algorithms
    • Algorithm Design Techniques
    • Specification
    • Abstraction
  • Composition and Decomposition
    • Notations for Algorithms
    • Composition
    • Decomposition
  • Iteration and Recursion
    • Invariants
    • Loop Invariant
    • Recursion
  • Introduction to C++
    • Introduction to C++
    • C++ Character Set
    • Lexical Units (Tokens)
    • I/O Operators
    • Sample program – A first look at C++ program
    • Execution of C++ Program
    • C++ Development Environment
    • Types of Errors
    • C++ Data Types
    • Data Types
    • Variables of Built-in-data Types
    • Formatting Output
    • Expression
    • Type Conversion in Expressions
  • Flow of Control
    • Introduction to Flow of Control
    • Statements
    • Control Statements
    • Selection Statements
    • Iteration Statements
    • Jump Statements
  • Functions
    • Introduction to Functions of C+++
    • Need for Functions
    • Types of Functions
    • C++ Header Files and Built-in Functions
    • User-defined Functions
    • Methods of Calling Functions
    • Different Forms of User-defined Function Declarations
    • Returning from Function
    • Recursive Function
    • Scope Rules of Variables - Local and Global Variables
  • Arrays and Structures
    • Arrays in C++
    • Two-dimensional Array
    • Array of Strings
    • Structures Introduction
  • Introducton to Object Oriented Programming Techniques
    • Programming Techniques
    • Programming Paradigms
    • Basic Concepts of OOP
    • Advantages of OOP
    • Disadvantages of OOP
  • Classes and Objects
  • Polymorphism
  • Inheritance
    • Inheritance
    • Need for Inheritance
    • Inheritance
    • Derived Class and Base Class
    • Visibility Modes
    • Overriding / Shadowing Base Class Functions in Derived Class
  • Computer Ethics and Cyber Security
    • Introduction to Computer Ethics and Cyber Security
    • Ethical Issues
    • Cyber Security and Threats
    • Introduction to Information Technology Act
  • Tamil Computing
    • Introduction to Tamil Computing
    • Tamil in Internet
    • Search Engines in Tamil
    • e – Governance
    • e-library
    • Tamil Typing and Interface Software
    • Tamil Office Automation Applications
    • Tamil Translation Applications
    • Tamil Programming Language
    • Tamil Information Interchange Coding Systems
    • Tamil Operating System
    • Organisation and Projects to Develop Tamil
  • Defining an Overloaded Operator 
  • Steps for overloading operator
  • Rules for overloading operators 
  • Types of situations in Type Conversion 

Operator overloading and type conversions

Overloading stands for "giving additional meaning to". We can overload all the operators except the following:  

  1. Class member access operator (· , · *) 
  2. Scope resolution operator ->  ::
  3. Sizeof operator. 
  4. Conditional operator (?:).

Defining operator overloading 

To define an additional task to an operator, we must specify what it means in relation to the class to which the operator is applied. This is done with a special kind of function, called the operator function. The general form of operator function is: 

return-type class-name : : operator op-to-be-overloaded (arg_list)  

     {  

         function-body // task defined 

     } 

The process of overloading involves following steps:  

  1. First, create a class that defines the data - type that is to be used in overloading operation. 
  2. Declare operator function in public part of class. It may be either a member function or a friend function. 
  3. Define the operator function to implement the required operations.

Rules for overloading operators   

  1. Only existing operators can be overloaded. New operators cannot be created.
  2. The overloaded operator must have at least one operand that is user defined type.
  3. We cannot change basic meaning of the operator. 
  4. Overloaded operators follow the syntax rules of the original operators.
  5. Certain operators cannot be overloaded. (See table 3.5).
  6. Certain operators cannot be overloaded by friend function . (See table 3.6)

Type conversions 

When constants and variables of different types are mixed in an expression, complier applies rules of automatic type conversion s. The assignment operation also causes automatic type conversion. The type of data on right of an assignment operator is automatically converted to the type of variable on left. Compiler does not support automatic type conversion for user defined data types. We need to design conversion routines by ourselves, if such operation is required. Three types of situations may arise : 

  1. Conversion from built in type to class type. 
  2. Conversion from class type to built in type  
  3. Conversion from one class type to another class type.
If you would like to contribute notes or other learning material, please submit them using the button below.
Advertisements
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×
Our website is made possible by ad-free subscriptions or displaying online advertisements to our visitors.
If you don't like ads you can support us by buying an ad-free subscription or please consider supporting us by disabling your ad blocker. Thank you.