【问题标题】:Pbl xcode C++ typedef struct toto totoPbl xcode C++ typedef struct toto toto
【发布时间】:2009-11-24 09:18:28
【问题描述】:

我正在使用 xcode 在 macOS X 10.6.2 上开发 C++ 项目。

我尝试在 Windows 上编译我的代码并且没有任何问题,我猜 Linux 正在运行,但我现在没有。

我的问题是 xcode 不接受这种指令:

struct direction {
double x;
double y;
double z;
double t; };

typedef struct direction direction;

这是我的错误:

/Users/sbarbier/dev/xcode/Infographie/TP9-RayTracing/RayTracing-Direction.h:22:0 /Users/sbarbier/dev/xcode/Infographie/TP9-RayTracing/RayTracing-Direction.h:22:错误:从“typedef struct direction direction”更改“direction”的含义

我正在使用 GCC4.2 并且没有更改任何内容。此代码适用于每个平台,任何人都可以帮助我吗?

【问题讨论】:

  • 我刚试了一下,好像可以在 Linux 上运行

标签: xcode macos struct g++ typedef


【解决方案1】:

这不是 C。在 C 中,要使用 struct,您必须使用关键字 struct

struct some_struct{ int i; };
struct some_struct myStruct;

这通常是这样缓解的:

typedef struct { int i; } some_struct;
some_struct myStruct;

在 C++ 中,这不是必需的。 direction 已经有一个类型,然后你试图创建一个同名的新类型,这很糟糕。取出整个typedef,不需要。

【讨论】:

    【解决方案2】:

    在 C++ 中,structclass 仅在声明或定义结构或类时使用。您可能需要 C 中的 typedef,但在 C++ 中它没有任何意义。

    【讨论】:

      猜你喜欢
      • 2021-02-21
      • 1970-01-01
      • 2011-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多