This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Difference between C and C++


Hi Jan,

Your question is somewhat off-topic for this list.  This list is for GCC
compiler related issues, and your question is a C versus C++ kind of
question.

But anyway, I'll take a stab at it.

As you've discovered, C++ does not support C99's explicit array member
initialization.

In C++, you'll want to use a map.

---- blah2.cpp ----
#include <map>
#include <cstdio> // C++

using namespace std;

enum Key { kPieceA, kPieceB, kPieceC };

map<Key, string> nm;

void InitNm() {
  nm[kPieceA] = "something A";
  nm[kPieceB] = "something B";
  nm[kPieceC] = "something C";
}

int main() {
  InitNm();
  printf("%s! %s!\n", nm[kPieceA], nm[Key(1)]);
}
-------------------

Sincerely,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]