为什么尽管我声明了一个不完整类型的自动实例,但这段代码还是编译并运行

why does this code compile and run despite me declaring an automatic instance of incomplete type

本文关键字:段代码 实例 代码 运行 编译 声明 管我 一个 类型 为什么      更新时间:2023-10-16

从技术上讲,下面给出的代码不应该编译和运行,因为我已经声明了一个不完整数据类型的自动实例,但它确实编译和运行了。请有人帮我解码一下。

 #include<iostream.h>
    #include<conio.h>
    void main()
    {
     class student;
     student s;
    getch();
    }

    class student 
    {
     int age;
     public:
     student();
     ~student();   
    };
    student::student()
{
 age=14;
}
student::~student()
{
 }`

它不是有效的ISO C++。

您的编译器可能会接受它,因为它不是ISO C++编译器
它是20世纪90年代早期的"C++"预标准版本的编译器。

ISO C++于1998年成立。在你不使用的语言中,合理化"技术上"应该发生什么或不应该发生什么是没有意义的。