Thread: declaration of "blah" shadows a parameter??

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    5

    declaration of "blah" shadows a parameter??

    Code:
    #include <string>
    
    using namespace std;
    
    
    class intSet{
    	protected:
    		int integer[10];
    		int numOfInts;
      public:
      	
      	intSet(){
      		for (int i=0; i<10; i++){
      			integer[i]=0;
      		}
      		numOfInts=10;
      	}
         	
      	intSet(int arg[]){
      		for (int i=0; i<10; i++){
      			integer[i]=arg[i];
      	  }
      	  numOfInts=10;
        }
      	
      
      	int getIndexOf(int index){
      		return integer[index];
      	}
    };
    
    
    class maxIntSet: intSet{
    	
    	public:
    		
    		maxIntSet(int input[]){
    			
    		intSet(input); // I intend to call the constructor of parent class
    		}
    		
    		int getMaxInt(){
    			int tempMax=integer[0];
    			for (int i=0; i<10; i++){
    				if (integer[i]>tempMax)
    					tempMax=integer[i];
    				}
    				return tempMax;
    		}
    			
    };
    As you can see, I intend to call the constructor of parent class in the child class, because there is no need to duplicate the code here. But compiler gives me warning says "declaration of 'intSet input' shadows a parater."

    so what's the correct way to call parent class constructor?

    Thanks.

  2. #2
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    Use an initializer list:
    Code:
    maxIntSet(int input[]): intSet(input)
    {
    }
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Once the constructor body is entered, the member variables have been initialised, and thus the parent's constructor has been invoked. What you should do is to use a constructor initialisation list:
    Code:
    maxIntSet(int input[]) : intSet(input) {}
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    May 2007
    Posts
    5
    thx guys, so helpful~

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  2. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM