【发布时间】:2012-07-08 20:45:36
【问题描述】:
我查看了之前的问题,但仍然不满意,因此我发布了这个。 我试图编译别人写的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 }
};
使用标准 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 行是哪几行?
-
你得到的是 C 代码,而不是 C++ 代码。试试 C 编译器。
-
你不是第一个遇到这个问题的人:stackoverflow.com/q/855996/1025391
标签: c++ c++11 initialization