小编San*_*iew的帖子

为什么在非指针结构上进行类型转换会出现语法错误

我正在使用 Visual C++ express 2008 尝试编译类似于以下的代码:

没问题

{
  ...
  AVRational test = {1, 1000};
  ...
}
Run Code Online (Sandbox Code Playgroud)

出现问题如下:

{
  ...
  AVRational test = (AVRational){1, 1000};
  ...
}
Run Code Online (Sandbox Code Playgroud)

给出了错误:

1>..\..\..\projects\test\xyz.cpp(1139) : error C2059: syntax error : '{'
1>..\..\..\projects\test\xyz.cpp(1139) : error C2143: syntax error : missing   ';' before '{'
1>..\..\..\projects\test\xyz.cpp(1139) : error C2143: syntax error : missing ';' before '}'
Run Code Online (Sandbox Code Playgroud)

其中 AVRational(ffmpeg.org 库)定义为:

typedef struct AVRational{
    int num; ///< numerator
    int den; ///< denominator
} AVRational;
Run Code Online (Sandbox Code Playgroud)

FFmpeg 带有一些预定义的值,例如

#define AV_TIME_BASE_Q (AVRational){1, …
Run Code Online (Sandbox Code Playgroud)

c c++ ffmpeg visual-c++

3
推荐指数
1
解决办法
1647
查看次数

标签 统计

c ×1

c++ ×1

ffmpeg ×1

visual-c++ ×1