Your SlideShare is downloading. ×
0
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Function class in c++
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Function class in c++

216

Published on

Published in: Education, Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
216
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
20
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Lec-07 Function,Class
  • 2. Inline Function Inline functions are functions where the call is made to inline functions. The actual code then gets placed in the calling program. Once you define an inline function, using the 'inline' keyword, whenever you call that function the compiler will replace the function call with the actual code from the function. General form inline datatype function_name(arguments)
  • 3. Inline Function #include <iostream> using namespace std; int func(int); void main( ) { int x; cout << "n Enter the Input Value: "; cin>>x; cout << "n The Output is: " << func(x); } inline int func(int x1) { return 5*x1; } Note:-Inline functions will save time and are useful if the function is very small. If the function is large, use of inline functions must be avoided.
  • 4. Function Overloading • Using same function name for different purposes is called function overloading. • Function will perform different operations depending on the argument list in the function call Ex. int add(int ,int) int add(int , float) int add(float ,int) int add(int ,int,int) • A function is executed when the function call matches the prototype with same number and type of argument.
  • 5. Function Overloading • Function selection involves the following steps.. 1. Tries to finds the exact match in which types of actual argument are same. 2. If actual match is not found then compiler uses the type coercion :promotion to find the match. 3. if conversion is possible to have multiple matches then compiler will generate the error. Ex . long sqr(long n) double sqr(double n) Function call sqr(10) cause the error.
  • 6. C structure revisited • Provides a method to packing together data of different type. Ex struct complex { int real; int img; }; struct complex c1,c2; Limitation of c structure: 1. c3=c1+c2 //illegal 2. Data hiding
  • 7. C++ structure • C++ supports all the features of the structures as defined in c. • C++ structure can have both function and data. • Support data hiding(by defining members as private). • Default members are public .
  • 8. Class • A class is a user defined data type • General form of class declaration class class_name { private: variable declaration; function declaration; public: variable declaration; function declaration; };
  • 9. Class • function and variable collectively called class members. • Variables declared inside the class is known as data member and function declared inside the class is known as member function. • Only the member function can have access to the private data member and private member function. • Default members are private.
  • 10. Class declaration • Class declaration:class item{ int number; //variable declaration float price; public: void getdata(int ,float); //function declaration void putdata(void); };
  • 11. Defining member function • Member function can be defined in two places 1. Outside the class definition. 2. Inside the class definition
  • 12. Outside the class definition • Genral form :Return_type class_name::function_name(parameter list) { function body; } Ex . void item :: getdata(int x,float y) { number=x; price=y; }
  • 13. Inside the class definition • Genral form :Return_type function_name(parameter list) { function body; } Ex . void getdata(int x,float y) { number=x; price=y; }
  • 14. Accessing members of a class • Accessing data members object_name.datamember; • Accessing member function object_name.function(actual parameters); item m; m.getdata(5,6.5) Note : Members are called by using their name only inside the member function.
  • 15. Private Member Function • A private member function can only be called by another function that is member of its class even an object can not invoke the private function of a class using the dot operator. Class sample { int main() int m; { void read(void) sample s1; public: s1.read(); //error void update(void); s1.update(); }; } void sample :: update(void) { read(); //simple call no object is used }

×