This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Difference between C and C++
- From: John Love-Jensen <eljay at adobe dot com>
- To: Jan Holesovsky <kendy at artax dot karlin dot mff dot cuni dot cz>, <gcc-help at gcc dot gnu dot org>
- Date: Mon, 11 Nov 2002 06:47:37 -0600
- Subject: 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