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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T02:32:55+00:00 2026-05-23T02:32:55+00:00

I have two class with a vector that holds instances of a third class.

  • 0

I have two class with a vector that holds instances of a third class.

Basically I have three classes:

  • Corporation
  • Market
  • Equities

Corporation and market can have 0..* equities and equities must be linked to 1 market and 1 corporation (to print values, etc…)

I don’t know how to do that properly. For me the problem is when I do one vector of equities in market and coporation, I can’t put a link in Equities for Corporation and Market because when the Equities.h is the first it don’t know Market and Corporation class found in Equities class. And if Corporation.h and Market.h are the first it say me than it don’t know the Equities class found in Corporation and Market class.

What is the best code to build the solution for this? I can’t say to VisualStudio to go away when he see a class than it never see already? (because the definition is just to the next so it change nothing … 🙁 ) It’s impossible in C++ to have in the first class : a link or a vectorof the second class and in the second class : a link or a vector of the first class without having a problem when we build the solution?

Edit:

It’s work, I wrote “class Equities; class Corporation; class Market;” and it didn’t care about the fact that it didn’t know these classes. Thank to everyone it was so quick! I will read your link when I will finish my job. 🙂

  • 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-23T02:32:56+00:00Added an answer on May 23, 2026 at 2:32 am

    The simplest way is to forward declare or prototype all the classes and types in a common header, place guards on that, and include the header from all your code files. For example:

    header.hpp:

    #ifndef COMMON_HPP
    #define COMMON_HPP
    
    class Corporation;
    class Market;
    class Equities;
    
    typedef std::shared_ptr<Corporation> CorpRef;
    
    typedef std::list<CorpRef> CorpList;
    
    #endif /*COMMON_HPP*/
    

    body.cpp:

    #include header.hpp
    
    class Corporation
    {
        static CorpRef Create();
    };
    

    and so on.

    If you’re using Visual Studio exclusively, you can use #pragma once in place of the #ifndef guards.

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

Sidebar

Related Questions

I have a base class, Parameter, and two derived classes: Scalar & Vector. In
suppose you have two (or more) classes with private member vectors: class A {
I have two classes class A { public string something { get; set; }
I have two classes, point and pixel: class point { public: point(int x, int
I have two implemented classes: class DCCmd : public DCMessage class DCReply : public
I have two classes in short here they are: public final class ServerMain {
Let just say that we have two classes, A and B . Here is
I have a vector-like class that contains an array of objects of type T
I have two classes: class Object { public: Object(); virtual void update(); virtual void
I have a vector class that has it's Equals(object obj) method overridden so that

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.