devxlogo

Forward Declaration of Classes and Structs

Forward Declaration of Classes and Structs

You can use the keywords class and struct in forward declarations interchangeably. For example:

 class X; // fwd declaration uses 'class'X *p;struct X // definition uses 'struct'{};void f(){ p=new X;}

size=3>
It works the other way around, too:

 struct X; X *p;class X {};

size=3>

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist