Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8932685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:22:06+00:00 2026-06-15T09:22:06+00:00

I want to write a chat room program of C++, and I will use

  • 0

I want to write a chat room program of C++, and I will use fork() after accept(),
all of the clients will communicate by shared memory, the following is part of my code,
I put a struct in shared memory, but i get compile error.
How can I fix it, or someone can give me an example, thanks!

typedef struct ClientList{
int pid[30];
int whoid[30];
string name[30];
bool online[30];
string ip[30];
int port[30];
string file[30][30];
int pid_who[30][30];
int onlineUser;
}ClientList;


/*Shared memory*/
int segment_id;
ClientList shared_memory;
struct shmid_ds shmbuffer;
int segment_size;
const int shared_segment_size = sizeof(shared_memory);

int main(int argc, char* argv[])
{
    /* Allocate a shared memory segment. */
    segment_id = shmget (IPC_PRIVATE, shared_segment_size, IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR);

    /* Attach the shared memory segment. */
    shared_memory = (ClientList) shmat (segment_id, 0, 0);
    printf ("shared memory attached at address %p\n", shared_memory);

    /* Determine the segment’s size. */
    shmctl (segment_id, IPC_STAT, &shmbuffer);
    segment_size = shmbuffer.shm_segsz;
    printf ("segment size: %d\n", segment_size);
}

The error message is
pipe.cpp: In function 「int main(int, char**)」:
pipe.cpp:57:55: 錯誤:對 「ClientList::ClientList(void*)」 的呼叫沒有匹配的函式
pipe.cpp:57:55: 附註:candidates are:
pipe.cpp:31:16: 附註:ClientList::ClientList()
pipe.cpp:31:16: 附註: candidate expects 0 arguments, 1 provided
pipe.cpp:31:16: 附註:ClientList::ClientList(const ClientList&)
pipe.cpp:31:16: 附註: no known conversion for argument 1 from 「void*」 to 「const ClientList&」
pipe.cpp:58:66: 錯誤:cannot pass objects of non-trivially-copyable type 「ClientList {aka struct ClientList}」 through 「...」

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T09:22:07+00:00Added an answer on June 15, 2026 at 9:22 am

    Use a pointer, not value

    ClientList* shared_memory;
         here ^
    
    shared_memory = (ClientList* ) shmat (segment_id, 0, 0);
                      and here ^
    

    Ah, and then your sizeof will look like this

    const int shared_segment_size = sizeof(ClientList);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write a simple chat application (for test use). The users and
I want to create SOCKET chat(server + clients) with private messaging. When client write
I want to write a console chat program in qt framework.I have a problem
Say I want to write a peer to peer chat application. And I use
I have been written chat program code for wired network. I want to write
I want to write an X-Chat plugin where users will be able to perform
I want to write a browser-chat and write an own server in c++, because
I want write a simple query which will fetch data from a table (which
I want to write a program in Prolog that confirms if a b-tree of
I want to write a simple chat-client in Ruby for the terminal. The Problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.