我看了一下前面的問題,但仍然不滿意,因此我發佈了這個。 我試圖編譯別人編寫的C++代碼。C++錯誤:'。'之前預期的主表達式令牌
/*
file1.h
*/
#include <stdio.h>
#include <stdlib.h>
typedef struct
{
struct
{
unsigned member1;
unsigned member2;
} str1;
struct
{
unsigned member3;
unsigned member4;
} str2;
struct
{
unsigned member5;
unsigned member6;
} str3;
} CONFIG_T;
/*
file1.c
*/
CONFIG_T cfg =
{
.str1 = { 0x01, 0x02 },
.str2 = { 0x03, 0x04 },
.str3 = { 0x05, 0x06 }
};
編譯與std C++ 11,我得到以下錯誤。爲什麼 '。'已在代碼 中使用,同時分配值?
home $$ g++ -c -std=gnu++0x initialze_list.cpp
initialze_list.cpp:34: error: expected primary-expression before ‘.’ token
initialze_list.cpp:35: error: expected primary-expression before ‘.’ token
initialze_list.cpp:36: error: expected primary-expression before ‘.’ token
我無法理解錯誤的原因。請幫忙。
哪些線是編號34,35,36? – 2012-07-09 12:48:32
您已獲得C代碼,而不是C++代碼。嘗試一個C編譯器。 – 2012-07-09 12:49:23
您不是第一個有此問題的人:http://stackoverflow.com/q/855996/1025391 – moooeeeep 2012-07-09 14:24:55