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

  • Home
  • SEARCH
  • 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 789923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T21:36:09+00:00 2026-05-14T21:36:09+00:00

I have a struct that’s defined with a large number of vanilla char* pointers,

  • 0

I have a struct that’s defined with a large number of vanilla char* pointers, but also an object member. When I try to statically initialize such a struct, I get a compiler error.

typedef struct 
{
    const char* pszA;
    // ... snip ...
    const char* pszZ;

    SomeObject obj;
} example_struct;

// I only want to assign the first few members, the rest should be default
example_struct ex = { "a", "b" };

SomeObject has a public default constructor with no arguments, so I didn’t think this would be a problem. But when I try to compile this (using VS), I get the following error:

error C2248: 'SomeObject::SomeObject' : cannot access private member declared in class 'SomeObject'

Any idea why?

Update: Here’s the definition of SomeObject

class SomeObject
{
    void operator=(const SomeObject&);
    SomeObject(const SomeObject&);
public:
    SomeObject()
        {
            // etc
        }

    // members snipped
}
  • 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-05-14T21:36:10+00:00Added an answer on May 14, 2026 at 9:36 pm

    Your initialization of ex performs copy-initialization. It takes the value on the right and uses it to initialize the variable on the left. For class-type members, the appropriate constructor is used. In your case, that means invoking the copy constructor for SomeObject, but you’ve made that constructor private, so the compiler is correct in telling you that SomeObject::SomeObject is a private member that can’t be accessed.

    Although the compiler is allowed to elide the call to the copy constructor and initialize ex.obj directly with the default constructor, that is an optional optimization; it still needs to be allowed to call the copy constructor.

    You can either give example_struct a constructor of your own and use that in place of brace initialization, or you can publicize SomeObject‘s copy constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct that contains pointers: struct foo { char* f; int* d;
In my C# application, I have a large struct (176 bytes) that is passed
I have class with a member function that takes a default argument. struct Class
I have a struct defined like follows as part of an object. I'm trying
I have a struct that only contains pointers to memory that I've allocated. Is
I have a function that takes a struct, and I'm trying to store its
I have this routine that calculates the seconds-to-date for a struct tm . On
I have a function that takes pointer to pointer to struct. struct ABC; void
I have a fairly simple const struct in some C code that simply holds
I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr {

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.