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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:07:35+00:00 2026-06-05T23:07:35+00:00

I have segmentation fault problem with my multiple class files project. Without making empty

  • 0

I have segmentation fault problem with my multiple class files project.

Without making empty classes and then pointers I get “XXX does not name a type” error.

How can I fix this or do this another way? I can not make class AA in class A.

main.cpp

#include "A.h"

A a;

int main() {
    while(true) {

    }
    return 1;
}

A.h

#ifndef A_H_
#define A_H_

class AA;

#include "AA.h"

class A {
public:
    A();
    virtual ~A();

    AA *aa;
    void run();
};

#endif /* A_H_ */

A.cpp

#include "A.h"


A::A() {
    // TODO Auto-generated constructor stub

}

A::~A() {
    // TODO Auto-generated destructor stub
}

void A::run() {
    aa->run();
}

AA.h

#ifndef AA_H_
#define AA_H_

#include <iostream>

class AA {
public:
    AA();
    virtual ~AA();

    void run();
};

#endif /* AA_H_ */

AA.cpp

#include "AA.h"

AA::AA() {
    // TODO Auto-generated constructor stub

}

AA::~AA() {
    // TODO Auto-generated destructor stub
}

void AA::run() {
    std::cout << "1";
}
  • 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-05T23:07:38+00:00Added an answer on June 5, 2026 at 11:07 pm

    All you need is an include of AA.h in A.cpp.

    This is a quite common scenario. Whe your interface needs one thing and your implementation needs other stuff. Not all includes should to be done in the .h file. Also this should not produce a segfault, it should be not compiling.

    On the same note, you are including iostream in the .h file, you are using it in the .cpp file, why not include it there instead?

    REREAD: You are not constructing your aa object.
    issue a

    aa = new AA();
    

    or similar in your constructor. Currently you are trying to access an object that has not been constructed.

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

Sidebar

Related Questions

I faced a problem using a Boost variant. I have a segmentation fault when
I have a segmentation fault problem occurring at the very end of my program.
I have a segmentation fault in the code below, but after I changed it
I am getting a segmentation fault and I cannot figure out why. I have
I have this output when trying to debug Program received signal SIGSEGV, Segmentation fault
I have a qApp that generates a segmentation fault only when a breakpoint is
Why does this code stop with segmentation fault : class MapFile { public: /*
I'm stuck with a weird problem. I have two files a.c and b.c as
I have a Segmentation fault in my multithreaded application that is becoming a headache.
I have implemented a class string, similar to std::string one. I have a problem

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.