Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 15th, 2006, 3:30 AM   #1
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
error: expected primary-expression...

I am in Linux, using g++ to compile.

My code looks like this:

This is the header:

class Test
{
   //...code... 
   
   public:
   void Function();
   
   //...code... 
};

In a cpp file I have the declaration:

void Test::Function(...)
{
   //....code...
}

I got this error when compiling:
....error: expected primary-expression before ‘void’....

What does this mean.
BTW, the code fragments are highly simplified and only a part of a programming project. But the interface is similar.
Can somebody help?
rup is offline   Reply With Quote
Old Apr 15th, 2006, 6:54 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You show an error that says, "expected primary-expression before 'void'..." Then you show us a snippet with everything before 'void' snipped out....hilarious. Incidentally, that's the definition in the cpp file, the declaration is in the class. Did you mean to have those three dots in the arg list in the definition and not up in the declaration?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 15th, 2006, 8:37 AM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
As Dawei said, the code snippets given do not give any useful information. It is better to find a SMALL but COMPLETE example that repeatably illustrates your problem (and post it verbatim in code tags). I recommend you read the sticky threads on "How to ask a question" as well .... they give advice on how to ask a question to increase your chances of getting a useful response.

The most common reasons the compiler would expect an expression before a function declaration or definition are a missing closing brace i.e. } or a missing semi-colon (or possibly both). But, given that you haven't provided enough information, that is only a stab in the dark.
grumpy is offline   Reply With Quote
Old Apr 15th, 2006, 8:48 AM   #4
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
Sorry for the incomplete post, should have followed intructions.
Here's the complete code:

The header gIPC.h:
#ifndef __GIPC_H__
#define __GIPC_H__

#include "gMsg.h"

class MessageQueue
{
	private:
		int qid;
		
	public:
		MessageQueue();
		~MessageQueue();
		void MsgSnd(Msg);
		void MsgRcv(Msg);
};

#endif // __GIPC_H__

The cpp, gIPC.cpp:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include "gIPC.h"

MessageQueue::MessageQueue()
{
	qid = msgget(key_t(1234), 0666|IPC_CREAT);
}

MessageQueue::~MessageQueue()
{
	msgctl(qid,IPC_RMID,0);
}

void MessageQueue::MsgSnd(Msg m)
{
	msgsnd(qid, void*(&m), m.GetMsgSize(),0);
}

void MessageQueue::MsgRcv(Msg m)
{
	msgrcv(qid, void*(&m), BUFSIZE, m.GetMsgType(), 0);
}

This is the error:
rup@ubuntu:~/gui$ make
g++ -c gIPC.cpp
gIPC.cpp: In member function ‘void MessageQueue::MsgSnd(Msg)’:
gIPC.cpp:18: error: expected primary-expression before ‘void’
gIPC.cpp: In member function ‘void MessageQueue::MsgRcv(Msg)’:
gIPC.cpp:23: error: expected primary-expression before ‘void’
make: *** [gIPC.o] Error 1
rup is offline   Reply With Quote
Old Apr 15th, 2006, 8:58 AM   #5
InfoGeek
Professional Programmer
 
InfoGeek's Avatar
 
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4 InfoGeek is on a distinguished road
SYSTEM CALL: msgsnd();                                                          

  PROTOTYPE: int msgsnd ( int msqid, struct msgbuf *msgp, int msgsz, int msgflg );
msgsnd function expects a struct msgbuf * as the second argument. Why are you passing a void *?
__________________
PFO - My daily dose of technology.
InfoGeek is offline   Reply With Quote
Old Apr 15th, 2006, 9:05 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
	msgsnd(qid, void*(&m), m.GetMsgSize(),0);
One doesn't declare a function's parameter type when one calls it, only when one declares or defines it. Did you perhaps mean to cast it?
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 15th, 2006, 2:11 PM   #7
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
I picked msgsnd from the book Beginning Linux Programming (Wrox).
It has the following prototype:
int msgsnd(int msqid, const void* msg_ptr, size_t msg_sz, int msgflag);
and is called this way in an example C program in the book:
msgsnd(msgid, (void*)&some_data, MAX_TEXT, 0);
where some_data is the structure:
struct msg{
    long int msg_type;
    char text[MAX_TEXT];
};

Yes, I meant to cast it.
rup is offline   Reply With Quote
Old Apr 15th, 2006, 2:28 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
So, did that clear your error message or not? Inquiring members want to know. It's the fee.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 16th, 2006, 9:26 AM   #9
rup
Newbie
 
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0 rup is on a distinguished road
Yes, it cleared my error message.

I hade written this:
msgrcv(qid, void*(&m), BUFSIZE, m.GetMsgType(), 0);

Because in C++ a cast is applied this way : void(variable) I had left it that way. Making it (void*)(&m) solves the problem.
rup is offline   Reply With Quote
Old Apr 16th, 2006, 9:57 AM   #10
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,260
Rep Power: 5 grumpy will become famous soon enough
Quote:
Originally Posted by rup
Because in C++ a cast is applied this way : void(variable) I had left it that way.
Rubbish. A cast is not applied "this way" in C nor in C++.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:08 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC