943,714 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Marked Solved
  • Views: 7044
  • C RSS
Jul 24th, 2009
0

The error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ <class name>

Expand Post »
Hi everyone, I'm new to C and have been given a C program to complete but found it includes many versions of the titled error for each class file.

Can anyone please explain why it occurs and how I could get rid of them?

Thanks,
Cleo

  1.  
  2. q2.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘spellChecker’

Example of a class:

  1. class spellChecker {
  2. protected:
  3. struct wordRecord* wordList;
  4.  
  5. public:
  6. spellChecker() {
  7. wordList=NULL;
  8. }
  9.  
  10. };
Similar Threads
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
156 posts
since Nov 2007
Jul 24th, 2009
0

Re: The error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ <class name>

its actually not a C program.Your program is in C++.Anyways
Which compiler you are using?
post a stand alone code so that we cant check the error!!
Reputation Points: 22
Solved Threads: 12
Junior Poster
Dream2code is offline Offline
144 posts
since Jun 2009
Jul 24th, 2009
0

Re: The error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ <class name>

Click to Expand / Collapse  Quote originally posted by Dream2code ...
its actually not a C program.Your program is in C++.Anyways
Which compiler you are using?
post a stand alone code so that we cant check the error!!
Okay, thanks for that, that was a stupid mistake, lol, I have not really got any experience with C++. I'm compiling it from the terminal window with g++ instead now.

If you don't mind, I have a new question with a new error.

I have a few of these:
error: ‘wordPointer’ was not declared in this scope
error: ‘malloc’ was not declared in this scope

so I passed wordPointer as a parameter (char* wordPointer)
but then found this brought me further errors for each variable I've defined within a structure or the class.

How do I allow these variables to be used publicly?

bool caseInsensitivelyEqual(char* s1, char* s2) {
	int i=0;
	bool same=true;
	while (s1[i] && s2[i] && same) {
	    same=(tolower(s1[i])==tolower(s2[i]));
	    i++;
	}
	  if (s1[i] || s2[i]) same=false;
	  return same;
	}
  
 Here are the variables I am using in my print method.
	struct wordRecord {
	  char* word;
	  struct wordRecord* next;
	};
class spellChecker { protected: struct wordRecord* wordList; public: spellChecker() { wordList=NULL; } };

and the other 2 variables I am using for my print method are within
my case sensitive spellChecker class

struct wordRecord *root;
	struct wordRecord *wordPointer;	
	root = malloc(sizeof( struct wordRecord)); 
	root -> next = 0; 
	root -> word = dest; 
	wordPointer = root;

print method: I have passed them as parameters below:

  1.  
  2. void printDict(char* wordPointer, char* root, char* word, char* next) {
  3. //Step through dictionary, printing each word
  4. wordPointer -> root;
  5. while(wordPointer != NULL) {
  6. printf("%s\n", wordPointer -> word);
  7. wordPointer = wordPointer -> next;
  8. }
  9. }

And the further errors I received:

error: request for member ‘root’ in ‘* wordPointer’, which is of non-class type ‘char’
error: request for member ‘word’ in ‘* wordPointer’, which is of non-class type ‘char’
error: request for member ‘next’ in ‘* wordPointer’, which is of non-class type ‘char’
Reputation Points: 39
Solved Threads: 12
Junior Poster
StephNicolaou is offline Offline
156 posts
since Nov 2007
Jul 24th, 2009
0

Re: The error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ <class name>

Hi there,

I think you have mistaked the pointer you should receive a wordRecord* and not a char* in the void printDict(char* wordPointer, char* root, char* word, char* next) in order you can use the word and next members in this way wordPointer -> word.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Leo71 is offline Offline
1 posts
since Jun 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Problem!!! Pls. help!!!
Next Thread in C Forum Timeline: Modifying the strstr function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC