![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
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? |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#4 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
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 |
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Jun 2005
Location: India, The great.
Posts: 435
Rep Power: 4
![]() |
SYSTEM CALL: msgsnd(); PROTOTYPE: int msgsnd ( int msqid, struct msgbuf *msgp, int msgsz, int msgflg );
__________________
PFO - My daily dose of technology. |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
msgsnd(qid, void*(&m), m.GetMsgSize(),0);
__________________
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 |
|
|
|
|
|
#7 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
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); msgsnd(msgid, (void*)&some_data, MAX_TEXT, 0); struct msg{
long int msg_type;
char text[MAX_TEXT];
};Yes, I meant to cast it. |
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#9 |
|
Newbie
Join Date: Jul 2005
Location: India
Posts: 14
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#10 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Excuse me?
![]()
__________________
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 |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|