Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert this C code to C++?

Tags:

c++

arrays

c

c++11

I have some arrays that are declared like this:

static double covalent_radius[256] = {
    [ 0 ] = 0.85,
    [ 1 ] = 0.37,
    ...
};

C++ doesn't allow this kind of declaration. Is there any way to achieve this?

like image 557
gsamaras Avatar asked Aug 24 '14 22:08

gsamaras


2 Answers

static double covalent_radius[256] = {
    0.85, /* ?,  Unknown    */
    0.37, /* H,  Hydrogen   */
    ...
};

It's C89, not C99 so I suppose it should work.

like image 108
Mabus Avatar answered Sep 28 '22 01:09

Mabus


Why don't you do this:

static double covalent_radius[256] = {
    0.85, /* 0: ?,  Unknown    */
    0.37, /* 1: H,  Hydrogen   */
    ...
};
like image 38
Steven Lu Avatar answered Sep 28 '22 01:09

Steven Lu