Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Forward-declare a typedef

I have got a large header file (~10000 lines) which is auto-generated by a script/program out of my control.

In order to avoid to include this file in the declaration of my class, I forward declare the few types I need:

--myclass.h

namespace bl {
   class TypeA;
   class TypeB;
}
// Other stuff and myclass definition...

Now it turns out that TypeA and TypeB are not class-names, but are instead defined inside the auto-generated file as:

typedef SomeUnspecifiedClassName TypeA;
typedef AnotherUnspecifiedClassName TypeB;

Where by SomeUnspecifiedClassName I mean that I can not forward-declare this type-name because it may change under various circumstances.

How can I forward-declare a typedef? (Can't use c++11)

like image 436
sbabbi Avatar asked Dec 20 '22 06:12

sbabbi


2 Answers

Simply - you can't. If you post your specific situations, though, there might be some workarounds to what you want to do.

like image 74
Jim Buck Avatar answered Dec 24 '22 00:12

Jim Buck


You can write a script that extracts the ...UnspecifedClassName from the typedef lines in your auto-generated source file. Then, this script would be the basis of your own auto-generated header file that would forward declare those classes, as well as your typedef statements to them. Your myclass.h file can then #include that header file.

like image 26
jxh Avatar answered Dec 24 '22 02:12

jxh