+ Reply to Thread
Results 1 to 2 of 2

Thread: What is name resolution in C++?

  1. #1

    What is name resolution in C++?

    What is name resolution in C++?

    Please provide some example of it.

  2. #2
    Junior Member
    Join Date
    May 2012
    Posts
    29
    Name resolution is used to get the proper match for the identifier for the current statement in given context.

    Below example should describe it:

    Code:
    class CNameResolution
    {
    private:
    	int a ;
    
    public:
    	int A ;
    
    	//there are two 'a' in this scope.
    	CNameResolution(int a)
    	{
    		this->a = a ; //two 'a' are differentiated by this pointer! 
    	}
    
    	void SetValue(int a)
    	{
    		this->a = a ;
    	}
    
    	void SetValue(double a)
    	{
    		this->a = (int) a ;
    	}
    } ;
    
    void UseNameResolution()
    {
    	int A = 10 ;//declare A
    	{
    		CNameResolution objNameResolution1(10) ;
    		{
    			int A = 20 ;
    
    			//two SetValue are differentiated by their argument!
    			objNameResolution1.SetValue(20) ;
    			objNameResolution1.SetValue(30.0) ;
    
    			objNameResolution1.A = A ;//A = 20 is being used!
    		}
    
    		objNameResolution1.A = A ;//A = 10 is being used!
    	}
    }
    Above example shows how function's name are resolved by their argument.

    Variable names are resolved using the scope of the variable.


+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts