Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9111055
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:24:58+00:00 2026-06-17T03:24:58+00:00

I am programming on linux using g++ and I often encounter the problem that

  • 0

I am programming on linux using g++ and I often encounter the problem that I need to use a class or data type in a header file which I define later, either at a later point in the header or in another header file.

For instance look at this header file:

class example
{
    mydatatype blabla;
};

struct mydatatype
{
   int blablainteger;
   char blablachar;
};

This will give error because mydatatype is used before its defined
so usually I change it like this:

struct mydatatype; // <-- class prototype
class example
{
    mydatatype *blabla; // <-- now a pointer to the data type
    // I will allocate the data during runtime with the new operator
};

struct mydatatype
{
   int blablainteger;
   char blablachar;
};

Now it works. I could often just put the definition above, or include the header which is needed, but I don’t want to include headers in a header or juggle with the definition order, it always gets messy.

The solution I showed usually works, but now I have encountered a new phenomenon. This time the datatype is not a class but a typedef, I cant use prototypes for a typedef and I don’t want to use the actual datatype which the typedef incorporates.. it’s messy too.
Is there any solution to this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T03:25:00+00:00Added an answer on June 17, 2026 at 3:25 am

    Firstly, the solution you’ve thought of (prototype and pointer), is unneeded, and slower than just implementing it without the pointer.

    The “proper” solution for this, would be creating seperate headers for each type, and then include them in your other header. That way it will always be defined! You can even make them so that they include eachother.

    However, if you’ve ever opened a .h file provided by g++, you’ve most likely seen this at the start of the header:

    #ifndef SOMETHING_H
    #define SOMETHING_H
    
    // Code
    
    #endif /* SOMETHING_H */
    

    This is to solve the issue of types redefining themselves.

    If they weren’t there, and you included the header file multiple times, the types would be redefined, and an error would be thrown. This makes it so that the types are always present, but never included twice.

    I hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OS: Linux(RedHat) Programming Language: C++ I need to create a daemon(process) for Linux using
I am programming in Linux using C/C++. I have a problem, i am trying
I'm programming C using Linux gcc with -std=c89 switch. I have a variable storing
I'm programming some C code using gcc -std=C89 switch on a Linux box. This
I have some problems to start programming using cocos2D on linux + android. I
I'm programming an application(client/server) in C++ for linux using epoll y pthreads but I
I am using Linux as my programming platform and C language as my programming
I am using C language and Linux as my programming platform. In my user-space
I'm quite fond of using GNU getopt , when programming under Linux . I
Is there any tutorial about using debuggers, when doing C programming on Linux (console

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.