Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C++ Linux
Hi everyone,
 
I have the following setup declare lots of stuff in a header file and use the header file in the main c file
 
So in the header file I have an enum declaration as so
 
void NewFunc(Stuff s,char c);
 
typedef enum Stuff
{ 
   Meet,
   Greet,
   Eat,
   Leave
};
 

//AND in main
#include "header.h"

//and try and use the function
void NewFunc(Stuff s,char c)
{
   //Blah Blah Blah......
}
 
It comes up with the following fault, when I make the program: expected ')' before s
 
Not sure if I declared the enum wrong or the makefile I use is broken :/.....
 
Using Ubuntu and VIM...
 
Help
Posted 21-Jan-13 5:01am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

The definition of NewFunc contains a forward reference (not allowed) to the enum, hence the error message. Move it below the enum definition.
  Permalink  
Comments
H.Brydon at 21-Jan-13 10:35am
   
Ding ding ding ... +5
Richard MacCutchan at 21-Jan-13 12:26pm
   
See my response to SA.
Marcus Kramer at 21-Jan-13 11:15am
   
+5.
Richard MacCutchan at 21-Jan-13 12:26pm
   
See my response to SA.
Sergey Alexandrovich Kryukov at 21-Jan-13 11:26am
   
5.
—SA
Richard MacCutchan at 21-Jan-13 12:26pm
   
Thanks guys, more points than I've received in one go for a long time.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

... and remove that typedef. That is an old C convention to declare enumarations as
 
typedef enum {
    // something
} MYENUM;
 
In C++ enums are first class citizens and you simply write
enum MyEnum {
    // something
};
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 21-Jan-13 11:26am
   
5!
—SA
nv3 at 21-Jan-13 11:39am
   
Thanks, SA!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Seems all your suggestions don't work.... removed the typedef, and yes I had thought about the scope issue of it being declared before the enum... I originally had it below the enum....
 
A bit quick to give each other +5 to your solutions that don't work.... :p
  Permalink  
Comments
Richard MacCutchan at 22-Jan-13 5:23am
   
Yes, our suggestions do work because most of us actually test them before posting here. Show the code you have now and any associated compiler messages.
Richard MacCutchan at 22-Jan-13 5:25am
   
Also, please do not post comments or questions as solutions. Use the "Have a Question or Comment?" button beneath our solutions to respond.
H.Brydon at 22-Jan-13 11:42am
   
Richard's comment that you use enum Stuff in the NewFunc forward declaration before defining "Stuff" is the cause of the error. nv3's comment that you should use newer syntax for the enum is also correct.
 
Both comments are correct and valid, solve the question you asked and show you how to improve your code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 315
1 OriginalGriff 233
2 Aajmot Sk 224
3 Richard MacCutchan 220
4 Marcin Kozub 210
0 OriginalGriff 7,853
1 Sergey Alexandrovich Kryukov 7,107
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,790


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100