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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:49:53+00:00 2026-05-14T16:49:53+00:00

Edit: Thanks folks, now I see my mistake. If I’m not wrong, because of

  • 0

Edit: Thanks folks, now I see my mistake.

If I’m not wrong, because of its nature in factory method there is cyclic dependency:

Base class needs to know subclasses because it creates them, and subclasses need to know base class. Having cyclic dependency is bad programming practice, is not it?

Practically I implemented a factory, I have problem above, even I added

#ifndef MYCLASS_H
#define MYCLASS_H
#endif

I’m still getting

Compiler Error C2504 'class' : base class undefined

And this error disappers when I remove subclass include from base class header.

  • 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-14T16:49:54+00:00Added an answer on May 14, 2026 at 4:49 pm

    Solution 1: don’t #include the derived class headers in the base class header, only in the base class cpp. The declaration of the factory method should not use the type of concrete classes returned, only the base type.

    Solution 2: use a separate factory class (or a factory method within a separate class) to create your objects. Then the cyclic dependency is totally eliminated. This is the preferred way.

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

Sidebar

Related Questions

Edit: Thanks @BlackFrog. I think I'm nearer now, but the values are still not
EDIT - Thanks all - I knew it would be simple...couldn't see the wood
Why new()/delete() is slower than malloc()/free()? EDIT: Thanks for the answers so far. Please
EDIT: SOLVED Thanks Brooks. Your question led me to keep digging into if the
Please let me know if you have any idea about it. Thanks EDIT What
EDIT: I figured it out from Bergi's answer in the end. Thanks Bergi. pubPrivExample
UPDATE: Solved. Thanks BusyMark! EDIT: This is revised based on the answer below from
EDIT: I have fixed all but two warnings now, so thank you all for
EDIT: See my answer below--> I am wanting to have a view that when
Edit: Thanks for the previous answers. but in fact I want to do it

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.