C++Builder Learn How To Use C++ Incomplete Return Types In Windows Development

FireWind

Свой
Регистрация
2 Дек 2005
Сообщения
1,957
Реакции
1,199
Credits
4,009
Learn How To Use C++ Incomplete Return Types In Windows Development
January 22, 2021 by Pabitra Dash

An incomplete type is a type that describes an identifier but lacks information needed to determine the size of the identifier. An incomplete type can be:
  • A structure type whose members you have not yet specified.
  • A union type whose members you have not yet specified.
  • An array type whose dimension you have not yet specified.
The void type is an incomplete type that cannot be completed. To complete an incomplete type, specify the missing information. The following examples show how to create and complete the incomplete types.
  • To create an incomplete structure type, declare a structure type without specifying its members. In this example, the ps pointer points to an incomplete structure type called student.
C++:
struct student *ps;
  • To complete an incomplete structure type, declare the same structure type later in the same scope with its members specified, as in
C++:
struct student{
int num;
}

Incomplete return type​

Let’s consider the following code.
C++:
class AClass; //forward declaration of AClass (incomplete type);
class UseAClass
{
   public:
      AClass returnAClass() {} // return a copy of incomplete type - AClass
}
In the above code Bororland C++ compiler flash compilation error “Incomplete result type AClass in function definition”. Because at this point compiler needs to know the members of AClass, only forword declaration won’t work.

Для просмотра ссылки Войди или Зарегистрируйся