我想在构造对象时在结构中启动数组的大小:
class someclass{
public:
someclass(int init_msgsz) { this->msgsz = init_msgsz; }
private:
int msgsz;
struct msgbuf {
long msqtype;
uint8_t msgtext[msgsz];
} send_message_buf, receive_message_buf;
};
Run Code Online (Sandbox Code Playgroud)
但有些事情是错的:-(任何人都帮帮我?
注意这个结构来自:msgrcv,msgsnd - 消息操作
#include <iostream>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdint.h> //uint8_t == unsigned char
#include <string.h>
class communication
{
public:
communication(key_t &init_key, int &init_msgflg, size_t init_msgsz);
~communication();
int send_msg(uint8_t *send_msg);
int receive_msg(uint8_t *rec_msg);
private:
int msqid;
key_t key;
int msgflg;
int msgsz;
size_t buf_length;
struct msgbuf {
long msqtype; …Run Code Online (Sandbox Code Playgroud)