answersLogoWhite

0


Best Answer

Yes you can use the same function name for a member function and an external function. They are primarily distinguished by the number and type of arguments they accept (the function signature). If they match exactly, then the scope resolution operator (::) is used to differentiate them by namespace. The class namespace is the class name itself. The external function uses global scope unless scoped to another namespace. When the scope is not explicitly stated, then the scope is implied by the call site.

Note that whenever there is any ambiguity about which function is implied, the compiler will emit an error indicating where the ambiguity lies, and the program will ultimately fail to compile.

User Avatar

Wiki User

10y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

Can we use the same function name for a member function of a class and an outside function in the same program file? If yes, how are they distinguished? If no, give reasons.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

#include<iostream.h>

class demo

{

public:

void display()

{

cout<<"\ni m in demo class";

}

};

void display()

{

cout<<"\ni m in outside the class";

}

void main()

{

display();

demo d;

d.display();

}

--------------------------------------------------------

output-

i m outside the class

i m in the demo class

---------------------------------------------------------

This answer is:
User Avatar

User Avatar

Wiki User

15y ago

Yeah, sure -- why have you not tested it yourself?

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Can you use the same function name for a member functoin of a class and an outside function in the same program file?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why do you member functions defined outside the class?

A member function of a class can be defined outside the class using scope resolution :: operator Thanks Rajneesh


How the member function can be undefined?

You cannot undefine a member function.


What is member fusion in c plus plus?

If you are asking about member functions. When we declare a function inside a class then that function becomes member function of that class and this function can access the whole class


How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


Can static member function be overloaded?

Yes. Any function can be overloaded. However you cannot override a static member function. Only instance members can be overridden.

Related questions

Why do you member functions defined outside the class?

A member function of a class can be defined outside the class using scope resolution :: operator Thanks Rajneesh


What is the meaning of x.getdata in c plus?

it mens u r calling de member function of de program


How the member function can be undefined?

You cannot undefine a member function.


What is member fusion in c plus plus?

If you are asking about member functions. When we declare a function inside a class then that function becomes member function of that class and this function can access the whole class


Who was the first member of the Vandal Patrol Program?

The first member of the Vandal Patrol Program was An8thg, the Vandal Patrol Program Coordinator.


In the ordered pair x y the value of y is a member of the?

x is a member of the function's domain, y is a member of the function's range.


What is the difference between friend function and normal member function?

We can access a Friend function from any other class in which friend function is introduced or declared even if the other class is not a member of first class. But when we use normal member function, we can have its access only in the derived classes of the first class. This is the basic difference between a friend function and a normal member function.


What is meant by extension?

extensible means to enhance the program with new capabilities. In c++, extensibility can be achieved by using virtual function. now first we discuss what is virtual function in c++. " C++ virtual function is a member function of a class, whose functionality can be over-ridden in its derived classes. The whole function body can be replaced with a new set of implementation in the derived class." Through this u can be able to promote extensibility in your program by using Virtual function. Very simple concept.


Can the members of the domain be in the members of the range and be a function?

Yes, the domain must correspond to only one member of the range in order to be a function in a member of the domain goes to more than one member of the range it then is a relation and not a function A function is a relation but a relation isnt always a function


Difference between member function and friend function?

1. Function - is normally refered to a C-style function which has a global level scope. As long as its declaration is visible in a file where it is being used, and the definition is available somewhere in the application, the linker will find the definition and link to it. It can be used anywhere in the application. 2. Member function - is normally referred to a C++Style method declared/defined inside of a C++ class. The scope for such member functions is the class. They are not accessible outside the class and are only accessible thru an object/instance of such a class. There are, of course, exceptions to this, such as static and friends.


How do you differentiate between a member function and normal function?

A normal function is any function that is not a member of any class. Normal functions that operate upon a class are referred to as non-member functions, however a non-member function can also be a member of another class. Any class may declare any non-member function to be a friend of the class, in which case the function becomes a friend function.A member function is a member of a class and may be declared static or non-static. Non-static member functions have the following 3 properties:Private access to the class members.Scoped to the class.Must be invoked against an object of the class (has a 'this' pointer).Static member functions have the first two properties only while friend functions have the first property only. Non-member functions that are not friends of the class have none of these properties.


Can static member function be overloaded?

Yes. Any function can be overloaded. However you cannot override a static member function. Only instance members can be overridden.