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 5838629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:29:18+00:00 2026-05-22T11:29:18+00:00

Is this allowable? class object { public: struct st_example { int i; int j;

  • 0

Is this allowable?

class object 
{
public:
    struct st_example {
        int i;
        int j;
        int c[d];
        st_example(int i_i, J_j, d_d) : i(i_i), j(j_j), d(d_d) {}
    };

    object(int i_ii, int j_jj, int d_dd)
    {
        struct st_example test(i_ii, j_jj, d_dd);
    }; // Constructor
};

So that:

object testObj(1,2,3);
  • 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-22T11:29:18+00:00Added an answer on May 22, 2026 at 11:29 am

    What’s d in st_example? I don’t see any variable d, so
    you can’t initialize it, nor use it in an expression.

    If you simply want st_example to contain an array whose size
    is determined at runtime, use std::vector. Trying to do it as
    you do cannot be made to work; you define a local st_example,
    and the compiler has to know how much space to allocate for it,
    at compile time.

    If all cases of st_example are allocated dynamically, there
    are some dirty tricks you can play:

    class st_example
    {
    public:
        int i;
        int j;
        int size;
        int* c() { return reinterpret_cast<int*>( this + 1 ); }
        int const* c() const { return reinterpret_cast<int const*>( this + 1 ); }
        void* operator new( size_t toAllocate, int n )
        {
            st_example* results =
                static_cast<st_example*>(
                    ::operator new( toAllocate + n * sizeof(int) ) );
            results->size = n;
            return results;
        }
        void operator delete( void* p )
        {
            ::operator delete( p );
        }
        void operator delete( void* p, int );
        {
            ::operator delete( p );
        }
        st_example(int i, int j)
            : i(i)
            , j(j)
        {
        }
    };
    

    (Formally, this is undefined behavior; The standard does not
    guarantee that values set in the operator new will still be
    there in the constructor. In practice, however, it will work.)

    Client code has to allocate using new (d) st_example(i, j),
    and access to elements of c is c()[i]. And in the more
    general case, you’ll likely have to worry about alignment.
    (Here, everything is int, so the alignment works out
    automatically.)

    I’d recommend sticking with std::vector, however. It’s a lot
    simpler, and a lot less fragile.

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

Sidebar

Related Questions

I have a class like this: public class Foo<T> : IEquatable<T> where T :
I'm trying to use the new multiple=multiple attribute allowable on elements. So far this
I want to validate usernames according to this schema: Allowable characters: letters, numbers, hyphen,
I've noticed that PHP seems to allow the following: <?php class StandAlone { public
i have a trouble and i need your help. Here's my code: public class
Consider this code: @Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) public @interface Bar { Foo foo() default FooImpl.FooConstant; }
This is a bit of a long shot, but if anyone can figure it
This is starting to vex me. I recently decided to clear out my FTP,
This is kinda oddball, but I was poking around with the GNU assembler today
This might seem like a stupid question I admit. But I'm in a small

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.