this code in c++

#include <iostream>
using namespace std;
int main()
{ return 0; }
struct X;
struct Y;
struct Y
{ X ox; };
struct X
{ Y oy; };

gives error as:"field `ox' has incomplete type"

Recommended Answers

All 2 Replies

three chairs rule

Basically you can resolve without using a pointer because a pointer (or reference) is the only thing you can declare in the presence of an incomplete type and either X or Y must be incomplete at the time the other is declared.

Any reason you don't want to use a pointer?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.