C的结构没有定义类型? [英] C structs don't define types?

查看:136
本文介绍了C的结构没有定义类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚开始学习C与Java的专业背景和一些(如果没有太多)C ++知识,我很惊讶,这并不用C工作:

I've just started learning C with a professional Java background and some (if no too much) C++ knowledge, and I was astonished that this doesn't work in C:

struct Point {
    int x;
    int y;
};

Point p;

p.x = 0;
p.y = 0;

看来,我已经使用结构 P 申报点作为类型或使用的typedef 。在是否该C99 code的作品?或者这是一个C ++的东西?

It seems that I have to declare p using struct Point as the type or using a typedef. Does this code works in C99? Or is this a "C++ thing"?

推荐答案

据我所知,它不应该没有的typedef 在C99无论是工作,(因为这仅仅是C工作)的方式,但它的工作在C ++中为结构在C ++中只是一个与公众所有成员在默认情况下。

As far as I know, it shouldn't work without a typedef in C99 either (as this is simply the way C works), but it does work in C++ as a struct in C++ is just a class with all members public by default.

这篇关于C的结构没有定义类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆