GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  Programming  >  C++
Go To First  |  Previous Question  |  Next Question 
 C++  |  Question 173 of 190    Print  
static and friend function in a class
use of static and friend function in a class


  
Total Answers and Comments: 1 Last Update: November 20, 2008     Asked by: jithinkm 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
November 20, 2008 14:38:49   #1  
matsp Member Since: November 2008   Contribution: 1    

RE: static and friend function in a class
The keyword static indicates that the function is part of the class, but does not take the object as the hidden "this" parameter. This is useful for example when you need a custom creation step of the class object [beyond what you can do in the constructor], or for singleton classes.

Static can also be used for variables, in which case it's a class-variable that is the only instance for all classes.

The keyword friend is used within a class to indicate that a class can access private member functions and private member variables even though the function is not part of the class itself. This allows the class to determine that certain functions are "friendly" or "trusted" and can be used to "look inside" the class.

--
Mats

 
Is this answer useful? Yes | No

 Related Questions

Class is a user-defined data type in C++. It can be created to solve a particular kind of problem. After creation the user need not know the specifics of the working of a class.   
Latest Answer : CLASS Specifies the criteria to handle  the instance of the problem.The entire set of data and methods associated with the problem can be bound together and implemented as type with the help of class. ...

Ø      Public, protected and private are three access specifiers in C++.  Ø      Public data members and member functions are accessible 
Latest Answer : Private:Can be data or method membersAre accessible ONLY thru other methods of the same class where they are declaredCannot be accessed thru a class instanceWill not be inheritedPublic:Can be data or method membersAre accessible globally from any function/method ...

 Structure: Initially (in C) a structure was used to bundle different type of data types together to perform a particular functionality. But C++ extended the structure to contain functions also. 
Latest Answer : Similar to difference in default access specifier, default inheritance too is different in Class Vs Structures. ...

As the name suggests, the function acts as a friend to a class. As a friend of a class, it can access its private and protected members. A friend function is not a member of the class. But it must be 
Latest Answer : Its the main feature of a class that  private member data of a class can be accessed only by the class' member functions. But there is an exception , A class can allow non-member functions and other classes to access its own private data, by ...

 A virtual function allows derived classes to replace the implementation provided by the base class. The compiler makes sure the replacement is always called whenever the object in question is actually 
Latest Answer :    A virtual function allows derived classes to replace the implementation provided by the base class. ...

A scope resolution operator (::), can be used to define the member functions of a class outside the class.  
Latest Answer : Scope resolution:As the name itself indicates,it resolves global scope to local scopeEx:int a=10;int main(){a=20;cout

Inheritance is the process of creating new classes, called derived classes, from existing classes or base classes. The derived class inherits all the capabilities of the base class, but can add embellishments 
Latest Answer : hi,Inheritance is the process of creating a new class called derived class from the existing class called base class. ...

"Poly" means "many" and "morph" means "form". Polymorphism is the ability of an object (or reference) to assume (be replaced by) or become many different forms 
Latest Answer : C++ enables polymorphism - The ability of obejcts of different classes related by inheritance respond differntly to the same function call. ...

 Classes and objects are separate but related concepts. Every object belongs to a class and every class contains one or more related objects.  Ø      A Class 
Latest Answer : Class is a combination of data member & member function where object is used for calling function In class we declare In object we call ...

  Function overloading: C++ enables several functions of the same name to be defined, as long as these functions have different sets of parameters (at least as far as their types are concerned). This 
Latest Answer : Here are some examples1) Function overloadingclass FuncOver {public:      // Constructors can also be overloaded.      FuncOver();      // Overloaded constructor.      ...


 Sponsored Links

 
Related Articles

Concepts of Object-Oriented Programming

Object Oriented JavaScript In this chapter you ll learn about OOP Object Oriented Programming and how it relates to JavaScript As an ASP NET developer you probably have some experience working with objects and you may even be familiar with concepts such as inheritance However unless you re already a
 

C++ Static Functions

C Static Functions Static member functions have a class scope and they do not have access to the this pointer of the class When a member is declared as static a static member of class it has only one data for the entire class even though there are many objects created for the class The main usage of
 

C++ Pure Virtual Function and Base Class

C Pure Virtual Function and Virtual Base Class In this C tutorial you will learn about pure virtual function declaration of pure virtual function and virtual base class virtual base class and how to implement a virtual base class explained with examples mosgoogle center What is Pure Virtual Function
 

C++ Function Passing Types

C Function Passing Types In this C tutorial you will learn about function passing types two types of arguments passing in functions passed by value  and  passed by reference are discussed here mosgoogle center The arguments passed to a function can be performed in two ways Passed
 

How to Access C++ Class Members

How to Access C Class Members In this C tutorial you will learn how to access Class members dot operator or class member access operator difference between struct and class and  scope resolution operator mosgoogle center It is possible to access the class members after a class is defined an
 

What is DECODE function used for?

DECODE is used to decode a CHAR or VARCHAR2 or NUMBER into any of several different character strings or numbers based on value. That is DECODE does a value-by-value substitution. For every value that is given in the DECODE function it makes an if then check and matches the value. The general format
 

printf() Function Return Value

What is the return value from printf() function? printf function always returns the number of characters printed. Let us understand this with an example: main() { int a=10; printf("%d",printf("%d %d %d", a,a,a)); } In this above program the inner printf i
 

How is the main() function declared?

The declaration of main can be done as int main() One more declaration that can be taken by main is command line arguments form int main(int argc, char *argv[]) or this can also be written as int main(argc, argv) int argc; char *argv[]; NOTE: It is not possible for one to declare the main
 

How does the function call within function get evaluated?

Whenever we have more than one function which is called for a finite number of times then such a function gets evaluated from inside out. Let us understand this concept with an example. For instance consider a function sample called within it 4 times as given in program below: main() { int a=50;
 

What happens when a variable is not initialized in main function?

When a variable is not initialized in main function it contains garbage value. This can be well seen from the example below main() { int x; printf(“%d”,x); z= sample() } sample() { printf(“Testing program”); } Output is   &n
 





About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape