how to declare this class function

This is a discussion on how to declare this class function within the C++ Programming forums, part of the General Programming Boards category; Ok here is the problem... I have a functions that calls the following: Code: for (x=1; x < pict.getWidth()-1; x++) ...

  1. #1
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572

    how to declare this class function

    Ok here is the problem... I have a functions that calls the following:
    Code:
    for (x=1; x < pict.getWidth()-1; x++) {
            for (y=1; y < pict.getHeight()-1; y++) {
                Color sum(0,0,0);
    
                for (int i=x-1, m=0; i <= x+1; i++, m++) {
                    for (int j=y-1, n=0; j <= y+1; j++, n++) {
                        sum = sum.add( pict.getPixel(i,j).times( matrix[m][n] ) ); ///THIS LINE IS WHERE THE PROBLEM COMES FROM
                    }
                }
                temp.setPixel(x, y, sum.divide( denom ) );
            }        
        }
    now, I can't get the proper declaration for 'add', here is what I have for that class:
    Code:
    class Color
    {
    public:
    
        // Define constructors ...
    	Color(int r, int g, int b);
    
    	Color();
    
        // Define functions to do the following to a color:
        // add, subtract, times, divide, complement (subtract from 255),
        // constrain (ensure values are between 0 and 255)	
    	Color add( Color c)
    	{
    		return Color( r + c.r,
    					  g + c.g,
                          b + c.b );
    	}
    
    	Color sum();
    
    	void subtract();
    	void times(int matrix);
    	void complement();
    	void constrain();
    	void devide();
    
    
        // Define functions to get the values of r, g, and b
    	char red() { return r; };
    	char green() { return g; };
    	char blue() { return b; };
     
    private:
        // Define r, g, b, as int
    	int r, g, b;
    	int height;
    
    };
    and just for completenes...here is the error I get:
    Code:
    c:\windows\desktop\image\imagemanip.cpp(376) : error C2664: 'add' : cannot convert 
    parameter 1 from 'void' to 'class Color'
    I know I'm overlooking something that is quite simple...any suggestions?

    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

  2. #2
    Registered User axon's Avatar
    Join Date
    Feb 2003
    Posts
    2,572
    Nevrmind...thisregard...I knew it was a simple mistake
    I replaced:
    Code:
    void times(int matrix);
        // with....
    Color times(int matrix);
    axon

    some entropy with that sink? entropysink.com

    there are two cardinal sins from which all others spring: Impatience and Laziness. - franz kafka

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 12:45 PM
  2. Callback function as class method
    By schifers in forum Windows Programming
    Replies: 39
    Last Post: 05-19-2008, 04:02 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-30-2005, 12:21 AM
  5. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21