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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T13:36:49+00:00 2026-05-10T13:36:49+00:00

If I create a class like so: // B.h #ifndef _B_H_ #define _B_H_ class

  • 0

If I create a class like so:

// B.h #ifndef _B_H_ #define _B_H_  class B { private:     int x;     int y; };  #endif // _B_H_ 

and use it like this:

// main.cpp #include <iostream> #include <vector>  class B; // Forward declaration.  class A { public:     A() {         std::cout << v.size() << std::endl;     }  private:     std::vector<B> v; };  int main() {     A a; } 

The compiler fails when compiling main.cpp. Now the solution I know is to #include 'B.h', but I’m curious as to why it fails. Neither g++ or cl‘s error messages were very enlightening in this matter.

  • 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. 2026-05-10T13:36:50+00:00Added an answer on May 10, 2026 at 1:36 pm

    The compiler needs to know how big ‘B’ is before it can generate the appropriate layout information. If instead, you said std::vector<B*>, then the compiler wouldn’t need to know how big B is because it knows how big a pointer is.

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

Sidebar

Related Questions

When I have a header file like this: #ifndef GAMEVIEW_H_ #define GAMEVIEW_H_ #include <SDL/SDL.h>
I have a C header file like this: #ifndef RENDERER_H #define RENDERER_H static int
I wanted to create my own Python exception class, like this: class MyException(BaseException): def
I'm trying to create a simple qDebug-like class I can use to output debug
There is some class wComplex with == operator. #ifndef WCOMPLEX_H #define WCOMPLEX_H #include <stdio.h>
I want to create a class like below class enumClass { int msdnEnum; std::string
I would like to create a class that creates and manages log files. I
I want to create a static class in PHP and have it behave like
I need to create at runtime instances of a class that uses generics, like
Is it completely against the Java way to create struct like objects? class SomeData1

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.