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 8466551
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:22:27+00:00 2026-06-10T15:22:27+00:00

I wondered if anyone could offer suggestions, without restructuring, on ways to get around

  • 0

I wondered if anyone could offer suggestions, without restructuring, on ways to get around this situation: I have a header which contains a class declaration and declares a number of classes that it uses by reference / pointer which is clearly good practice compared to simply including the headers for those classes.

struct Foo;

struct Bar;

struct MyStruct
{
    void doIt( const Foo* foo );

    void doIt( const Bar* bar );
};

However, while in the example above Foo is a class, Bar is actually a typedef of a class as per the crude example below:

#include <fd_ex.h>

struct Foo
{
   int a;
};

struct Bar_
{
   int a;
};

typedef Bar_ Bar;

This causes some problems as predeclaring struct Bar is obviously not correct – Bar is not a struct:

"fd_ex.cpp", line 13: Error: Multiple declaration for Bar.
"fd_ex.cpp", line 19: Error: The name Bar is ambiguous, Bar and Bar.
2 Error(s) detected.

I don’t want to expose Bar_ if possible, mainly because in real life this could be very much more complicated than this example.

However, if I have no control over the struct declaration and typedef for Bar, are there any techniques I can use in the header for MyStruct to keep with the spirit of pre-declaring Bar?

  • 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-10T15:22:29+00:00Added an answer on June 10, 2026 at 3:22 pm

    you can forward declare the struct itself:

    struct Bar_;
    
    typedef Bar_ Bar; 
    
    class MyClass
    {
      void DoIt( Bar* );
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wonder if anyone could offer their advice on this one. I have some
So I have this regex problem and wondered if anyone could help me out?
I wondered if anyone could shed some light on the way in which layers
I'm having the following problem and wondered whether anyone could see why this is
I'm having a little trouble attacking this problem and wondered if anyone could push
I'm learning about composite UIs at the moment and I wondered if anyone could
I have a 3 column data frame which looks a little like this: id
Just wondered if anyone could help, im getting the warning above with the following
I seem to have a glitch on in Internet Explorer and wondered if anyone
Just wondered if anyone could point me in the right direction of storing multiple

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.