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 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 anyone tell me how to hide the header in DevExpress gridcontrol..?? I'm using
can any one tell me how can change this java code into objective c.is
Can we do following in SQL Server 2005 query with convert function. MaxRegID =
Can anyone give me an example of how to return the following json simply
Can anybody tell what is the best(easy) way to sort the following string 'index'
can someone explain why the compiler accepts only this code template<typename L, size_t offset,
Can I register a .Net COM class with the SingleUse -flag? The reason I
Can't work out a way to make an array of buttons in android. This
Can we close all known/unknown connections to database with the code? I'm using Access
Can't seem to get the Back Button to appear in a UINavigationController flow. I

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.