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

The Archive Base Latest Questions

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

I can’t seem to wrap my head around the reason the following code won’t

  • 0

I can’t seem to wrap my head around the reason the following code won’t compile.

In my header file I declared an array as a static class member:

class foo {
private:
#define SIZE 50
static char array[SIZE];
// further code goes here
}

In the implementation, I have to initialize the array.

char foo::array[SIZE] = new[] char[SIZE];

This yields me an error everytime – the compiler says:

cannot convert from ‘char *’ to ‘char [50]’

Why does the compiler interpret new[] char[SIZE] as char*?

  • 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-18T11:51:42+00:00Added an answer on May 18, 2026 at 11:51 am
    1. There’s no such thing as new [] . You need to remove the [].
    2. Because ::operator new returns a pointer, not an array. Pointers are not arrays, and trying to treat the two interchangeably will result in pain. Just because arrays will decay into pointers doesn’t mean that arrays are pointers.
    3. foo::array[SIZE] is already static — there’s no need to allocate storage for it in any case.
    4. This looks like you’re coming from a Java or C# background, where arrays are reference types. Arrays are not reference types in C++. When you declare the array the storage for it is implicit. In your case the storage is going to be where all the other statics are; if the array was just written that way without static in a function then it would be allocated on the stack.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone thoroughly explain the last line of the following code: def myMethod(self): #
Can someone tell me where I'm going wrong here? basically I've written some code
Can we use javap in our own java code in a programmable way? for
Can someone please explain how this code is working for me? I don't understand
Can I write this with less code, also is .click(function preferred for mobile or
Can any one help me in sorting this out in sed/awk/perl Input file Start
Can someone help me? I am trying to do something like the following: #include
Can anyone can confirm the best idea for storing jquery code, initially i was
can someone tell me why sed won't remove my NULLs? this is on OS
Can anybody please explain what is happening below;how does the following bit shift works?

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.