-
prototype functions
I'm trying to learn how to do a prototype function and this is what is in a C++ book. I typed it out in Visual Studio, but it doesn't seem to work.
any ideas why?
Code:
//draws a triangle
void drawTriangle()
{
drawIntersect();
drawBase();
}
// File: stickFigure.cpp
// Draws a stick figure
#include <iostream>
using namespace std;
// Fucntions used ...
void drawCircle(); // Draws a circle
void drawTriangle(); // Draws a triangle
void drawIntersect(); // Draws intersecting lines
void drawBase(); // Draws a horizontal line
int main()
{
// Draw a circle.
drawCircle();
// Draw a triangle
drawTriangle();
// Draw intersecting lines.
drawIntersect();
return 0;
}
// Draw a circle
void drawCircle()
{
cout << " * " << endl;
cout << " * * " << endl;
cout << " * * " << endl;
} // end drawCircle
// Draws a triangle
void drawTriangle
{
drawIntersect();
drawBase();
} // end drawTriangle
// Draws intersecting lines
void drawIntersect()
{
cout << " /\\ " << endl;
cout << " / \\ " << endl;
cout << " / \\ " << endl;
} // end drawIntersect
//Draws a horizontal line
void drawbase()
{
cout << " _ _ _ _ _ _ " << endl;
} // end drawbase
-
-
here are the error messages:
error C3861: 'drawIntersect': identifier not found
error C3861: 'drawBase': identifier not found
error C2365: 'drawIntersect' : redefinition; previous definition was 'formerly unknown identifier'
error C2365: 'drawBase' : redefinition; previous definition was 'formerly unknown identifier'
error C2470: 'drawTriangle' : looks like a function definition, but there is no parameter list; skipping apparent body
error C2365: 'drawIntersect' : redefinition; previous definition was 'formerly unknown identifier'
7 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
Right. Remove all the code that is above:
Code:
// File: stickFigure.cpp
// Draws a stick figure
-
cool, that made it go from 7 errors to only 1:
error C2470: 'drawTriangle' : looks like a function definition, but there is no parameter list; skipping apparent body
I googled error C2470 and this is what it says:
Code:
Visual C++ Concepts: Building a C/C++ Program
Compiler Error C2470
Error Message
'function' : looks like a function definition, but there is no parameter list; skipping apparent body
A function definition is missing its argument list.
The following sample generates C2470:
Copy Code
// C2470.cpp
int MyFunc {}; // C2470
void MyFunc2() {}; //OK
int main(){
MyFunc();
MyFunc2();
}
-
Basically, it is saying that you forgot about the parentheses, i.e., (), when defining your MyFunc function.
By the way, are you changing your error messages? For one thing, the line number is missing, and the error message does not seem to be as informative as I would expect.
-
sorry, I probably didn't cut&paste enough error info.
I did forget the parentheses, now I understand what that sample meant, but for some reason it isn't wanting to work now that I fixed that.
error message:
1>------ Build started: Project: prototypeStickFigurePage124, Configuration: Debug Win32 ------
1>Compiling...
1>prototypeStickFigurepage124.cpp
1>Linking...
1>prototypeStickFigurepage124.obj : error LNK2019: unresolved external symbol "void __cdecl drawBase(void)" (?drawBase@@YAXXZ) referenced in function "void __cdecl drawTriangle(void)" (?drawTriangle@@YAXXZ)
fatal error LNK1120: 1 unresolved externals
1>prototypeStickFigurePage124 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
-
-
Code:
// File: stickFigure.cpp
// Draws a stick figure
#include <iostream>
using namespace std;
// Fucntions used ...
void drawCircle(); // Draws a circle
void drawTriangle(); // Draws a triangle
void drawIntersect(); // Draws intersecting lines
void drawBase(); // Draws a horizontal line
int main()
{
// Draw a circle.
drawCircle();
// Draw a triangle
drawTriangle();
// Draw intersecting lines.
drawIntersect();
return 0;
}
// Draw a circle
void drawCircle()
{
cout << " * " << endl;
cout << " * * " << endl;
cout << " * * " << endl;
} // end drawCircle
// Draws a triangle
void drawTriangle()
{
drawIntersect();
drawBase();
} // end drawTriangle
// Draws intersecting lines
void drawIntersect()
{
cout << " /\\ " << endl;
cout << " / \\ " << endl;
cout << " / \\ " << endl;
} // end drawIntersect
//Draws a horizontal line
void drawbase()
{
cout << " _ _ _ _ _ _ " << endl;
} // end drawbase
-
Spot the difference:
Code:
void drawBase(); // Draws a horizontal line
Code:
//Draws a horizontal line
void drawbase()
{
cout << " _ _ _ _ _ _ " << endl;
} // end drawbase
-
Looks like I have a lazy shift finger, I know to check for those now...
Thanks for your help :)
-