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

  • Home
  • SEARCH
  • 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 6742545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:51:22+00:00 2026-05-26T11:51:22+00:00

So, thanks to this website, I found the answer to my previous problem. I’m

  • 0

So, thanks to this website, I found the answer to my previous problem. I’m adding a function to a class in a GNU automake project that uses a pointer to a doc object. Dependencies were included in the Makefile.am file to include doc.h and plsa.h in the respective order. However, when I compiled, I would get a doc has not been declared error. Then, I tried adding the #include statement here, which gives a previous redefinition of 'class doc' error.

I learned that I have to declare doc by using the class doc; line commented out below; however, I thought that this was only necessary if I was declaring a function that passes the object by value. Can someone explain to me why the #include is incorrect in this case?

#include "doc.h"
//class doc;
class plsa {
    // ...
    int infer(doc *trset, int maxiter, double noiseH);
}
  • 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-05-26T11:51:23+00:00Added an answer on May 26, 2026 at 11:51 am

    Why the Redefinition errors?
    Please ensure that your header files have appropriate Header Guards/Include Guards.It is most likely that you have missed adding header guards and hence that causes multiple class definitions due to the header getting included multiple times.

    Why Forward Declaration is okay in this case?
    When instead of including the header file you add the line:

    class doc;
    

    It Forward declares the class doc which means for compiler it is an Incomplete type. With Incomplete types, One cannot create objects of it or do anything which needs the compiler to know the layout of docor more than the fact that doc is just an type.
    i.e: The compiler does not know what are its members and what its memory layout is.
    But Since pointers to all objects need just the same memory allocation, You can use the forward declaration when just reffering to an Incomplete type as a pointer.

    In this case the only way in which doc is being referenced is an pointer to the class doc and hence the Forward declaration will work as well.

    BottomLine:
    Including the header file should work for you If you have proper Inclusion Guards in-place.
    And there is nothing wrong with it.
    However, Forward declaring the class should also work for you because of the reasoning given above.Note that forward declarations are usually used in case where there is a Circular Dependency of classes.

    Which is better Include header File or Forward Declaration?
    Including the header file just copy pastes the code from the header to wherever the file was included, which basically could lead to:

    • Increase in compilation time
    • Pollution of global namespace.
    • Potential clash of preprocessor names.
    • Increase in Binary size(in some cases though not always)

    Forward Declaration has its own limitations on how the Incomplete type can be used further on.
    With Incomplete type you can:

    • Declare a member to be a pointer or a reference to the incomplete type.
    • Declare functions or methods which accepts/return incomplete types.
    • Define functions or methods which accepts/return pointers/references to the incomplete type (but without using its members).

    With Incomplete type you cannot:

    • Use it as a base class.
    • Use it to declare a member.
    • Define functions or methods using this type.

    Given the possibility(due to above limitations on Incomplete type usage) One should prefer Forward Declaration over Including Header.

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

Sidebar

Related Questions

I understand the problem that OSGI solved thanks to this question.... What does OSGi
Now that I can make useful user controls in WPF (thanks to this stackoverflow
I'm debbuging a web application that has a WebSite and a class library containg
So I have this website that will be accessed via an SSL connection (
I've tried doing my research on this, found this website: http://www.lullabot.com/blog/importexport-large-mysql-databases and still am
I'm trying to design a website for my mums backpackers business. The problem that
Thanks to this question (click me!) , I have the Source property of my
I am using Vim for windows installed in Unix mode. Thanks to this site
I added ASP.NET MVC manually to an existing WebForms application... thanks to this tutorial
Thanks for reading this. I am dynamically generating some data which includes a select

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.