errors &constructor pseudo return
Why do I get the errors :" ./rmt.cpp: In function `int main()':
../rmt.cpp:14: error: no matching function for call to `CMesQueue::CMesQueue(int&)'
../CMesQueue.hpp:27: note: candidates are: CMesQueue::CMesQueue(const CMesQueue&)
../CMesQueue.hpp:50: note: CMesQueue::CMesQueue() "
for the code below (I pointed the two errors with a comment in the code)?
Also , is there a way to make the constructor to modify a member variable like qid from the class CMesQueue ?, so I can put the code from the method " int CMesQueue::msg_create(std::string filepath)" in the constructor ? If the constructor could return something then I could simply make it return the qid .. but the constructor cannot return anything .. so how can I put the code from that method I mentioned above in the constructor ? and ..somehow be able to return the qid variable to the member variable qid, so other meehods (which i'll add) like send , receive can use it ..
Thank you !
#ifndef CMESQUEUE_HPP_
#define CMESQUEUE_HPP_
#include <sys/msg.h>
#include <sys/ipc.h>
#include <string>
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <iostream>
struct mymsgbuf{
long mtype;
char mtext[50];
pid_t pid;
};
using namespace std;
class CMesQueue
{ //error:note:"../CMesQueue.hpp:27: note: candidates are: CMesQueue::CMesQueue(const CMesQueue&)"
public:
CMesQueue();
//CMesQueue(int,std::string);
~CMesQueue();
//int CMesQueue::msg_create(char fname[50]);
int CMesQueue::msg_create(std::string filepath);
/*
* ID_2
*/
struct mymsgbuf qbuf;
int qid;
protected:
private:
};
CMesQueue::CMesQueue()
{ //error : "../CMesQueue.hpp:50: note: CMesQueue::CMesQueue() "
}
CMesQueue::~CMesQueue()
{
int a;
a=msgctl(qid,IPC_RMID,0);
}
int CMesQueue::msg_create(std::string filepath)
{
key_t mykey=ftok(filepath.c_str(),'b');
if((qid=msgget(IPC_PRIVATE,IPC_CREAT|0660))==-1) perror("eroare msgget");
return qid;
}
|