How to create function parameters

Hi, I am having some trouble creating parameters to a function. As it stands, a header file contains the function

declaration / prototype, the main codefile(.cpp) contains the call to function and the actual function code

itself. I am trying to implement parameters into the function(which are variables from within the function code

itself.

CURRENTLY:

In header file:

void DrawSquare(COLOUR );




Call to function in mainfile:

DrawSquare(Default_Colour ); //This call to Drawsquare function is part of another function.



Function code in mainfile (situated after the previous call to function)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
void DrawSquare(COLOUR c )   //draws a square
{
	float y_start = m_iMoveY;
	float y_end = 50 + m_iMoveY;
	float x_start = 200 + m_iMoveX;
	float slope_left = -0.5;
	float x_end = 250 + m_iMoveX;
	float slope_right = 0.5;
	//Note no protection to keep in screen bounds...
	for ( int j = y_start; j <y_end; j++)
	{
		for( int i = x_start; i < x_end; i++)
		{
			Plotpix( i, j, c.r, c.g, c.b );

		}
		x_end = x_end + slope_right;
		x_start = x_start + slope_left;
		y_end = y_end + slope_right;
	}
}

AFTER MY CHANGES:


I changed the declaration in the header file to:

void DrawSquare (float x_start, float x_end, float y_start, float y_end, float slope_left, float slope_right,COLOUR );


I changed the call to the function in the mainfile to:


DrawSquare (float x_start, float x_end, float y_start, float y_end, float slope_left, float slope_right,COLOUR c );



And finally I changed the function code in the mainfile to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void DrawSquare (float x_start, float x_end, float y_start, float y_end, float slope_left, float slope_right,COLOUR 
c)
{
	 y_start = m_iMoveY;
	 y_end = 50 + m_iMoveY;
	 x_start = 200 + m_iMoveX;
	slope_left = -0.5;
	x_end = 250 + m_iMoveX;
	 slope_right = 0.5;
	//Note no protection to keep in screen bounds...
	for ( int j = y_start; j <y_end; j++)
	{
		for( int i = x_start; i < x_end; i++)
		{
			Plotpix( i, j, c.r, c.g, c.b );

		}
		x_end = x_end + slope_right;
		x_start = x_start + slope_left;
		y_end = y_end + slope_right;
	}
}


Can anyone seem any problems with what I did, compared to what it was before I altered the header file, call to function, and the function code itself.

Thanks a lot
//

Errors i am getting are:

1>.\MyCode.cpp(233) : error C2660: 'DrawSquare' : function does not take 0 arguments
1>.\MyCode.cpp(233) : error C2144: syntax error : 'float' should be preceded by ')'
1>.\MyCode.cpp(233) : error C2059: syntax error : ')'


all these errors are pointing to the call to function in the main .cpp file.
You need to show us the main function where the call is made. Post a complete example that demonstrates the problem.
Function where call is made:
1
2
3
4
5
6
7
8
9
10
void DrawImage( )
{
	POLYGON polyTempP, polyTempQ, polyTempQT;	// Temporary polygons for copying transformed, projected / clipped
												// versions of scene polys before drawing them. 
	int iCurrentPoly;							// Current polygon in process
	
	if ( m_iNumOfPolys <= 0 )
		 DrawSquare(float x_start, float x_end, float y_start, float y_end, float slope_left, float slope_right,COLOUR c );		// This draws the square you see, replace with Trapezium, and later Polygon
	else
		m_iOurFrameCount++;	// Increment frame counter if we have a polygon to draw 


And previously it was:

1
2
3
4
5
6
7
8
9
10
void DrawImage( )
{
	POLYGON polyTempP, polyTempQ, polyTempQT;	// Temporary polygons for copying transformed, projected / clipped
												// versions of scene polys before drawing them. 
	int iCurrentPoly;							// Current polygon in process
	
	if ( m_iNumOfPolys <= 0 )
		DrawSquare(Default_Colour );		// This draws the square you see, replace with Trapezium, and later Polygon
	else
		m_iOurFrameCount++;	// Increment frame counter if we have a polygon to draw 
You aren't passing any parameters in the new call. It looks like you are just copying the function prototype.

You want:
func(1, 2, 3, etc);
Not:
func(float a , etc);
when you are calling the function. Look at how it was before; notice how it wasn't specifying types, just passing parameters?
Topic archived. No new replies allowed.