Reputation: 2458
I am writing a program that is supposed to help me learn about enumeration data types in C++. The current trouble is that the compiler doesn't like my enum usage when trying to use the new data type as I would other data types. I am getting the error "redeclared as different kind of symbol" when compiling my trangleShape function. Take a look at the relevant code. Any insight is appreciated! Thanks!
(All functions are their own .cpp files.)
header file
#ifndef HEADER_H_INCLUDED
#define HEADER_H_INCLUDED
#include <iostream>
#include <iomanip>
using namespace std;
enum triangleType {noTriangle, scalene, isoceles, equilateral};
//prototypes
void extern input(float&, float&, float&);
triangleType extern triangleShape(float, float, float);
/*void extern output (float, float, float);*/
void extern myLabel(const char *, const char *);
#endif // HEADER_H_INCLUDED
main function
//8.1 main
// this progam...
#include "header.h"
int main()
{
float sideLength1, sideLength2, sideLength3;
char response;
do //main loop
{
input (sideLength1, sideLength2, sideLength3);
triangleShape (sideLength1, sideLength2, sideLength3);
//output (sideLength1, sideLength2, sideLength3);
cout << "\nAny more triangles to analyze? (y,n) ";
cin >> response;
}
while (response == 'Y' || response == 'y');
myLabel ("8.1", "2/11/2011");
return 0;
}
triangleShape shape
# include "header.h"
triangleType triangleShape(sideLenght1, sideLength2, sideLength3)
{
triangleType triangle;
return triangle;
}
Upvotes: 1
Views: 8767
Reputation: 138357
Your problem has nothing to do with enums. The problem line is this line in your triangleShape definition:
triangleType triangleShape(sideLenght1, sideLength2, sideLength3)
You're missing the types for your parameters and some compilers such as gcc default to int
(although this isn't standard behaviour so you should never rely on it). Since the function definition uses float
s the compiler sees it as redeclaring it differently. You should use specify float
s in the implementation:
triangleType triangleShape(float sideLenght1, float sideLength2, float sideLength3)
Upvotes: 6