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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:59:40+00:00 2026-05-31T12:59:40+00:00

#include <iostream> using namespace std; class Street; class CrossStreet { private: char m_chName; Street*

  • 0
#include <iostream>

using namespace std;

class Street;

class CrossStreet

{

        private:

             char m_chName;
             Street* m_acLoS;
             int m_nNoS;
             static int m_nCSid;
        public:
             CrossStreet()
             {
                  Init();
                  m_chName = m_nCSid;
             }
             CrossStreet(char chName)
             {
                  Init();
                  m_chName = chName;
             }

             /** Problem is here **/
             void AddStreet(Street* const cStreet)
             {
                  m_acLoS[++m_nNoS] = cStreet;
             }

             ~CrossStreet()
             {
                  delete[] m_acList;
             }

             void Init()
             {
                  m_nNoS = 0;
                  m_acLoS = 0;
                  m_nCSid++;
             }

             friend class Street;
};

class Street

{

         private:

              int m_nDistance;

         public:

              Street(CrossStreet& cHead, CrossStreet& cTail, int nDistance)
              {
                   CreateStreet(cHead,cTail,nDistance);
              }

              void CreateStreet(CrossStreet& cHead, CrossStreet& cTail, int nDistance)
              {
                   m_nDistance = nDistance;
                   cHead.AddStreet(Street* const THIS);
                   cTail.AddStreet(Street* const THIS);

              }

};

when I compile above code, this throw error:

-->>invalid use of incomplete 'struct Street'
-->>forward declaration of 'struct Street'

function AddStreet of an object of ‘CrossStreet’ was called at an object of ‘Street’, to add ‘THIS street object to member variable of CrossStreet object. So I think I can use THIS pointer in this case but it not compile.

  • 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-31T12:59:41+00:00Added an answer on May 31, 2026 at 12:59 pm

    There is no such things as a THIS pointer. There is a this pointer though. So your code in CreateStreet is invalid (and not only for that). The correct syntax would be:

    cHead.AddStreet(this); // no cast needed
    

    The problem in AddStreet is that you have defined m_acLoS as a pointer-to-Street. So m_acLoS[x] is of type Street, and not Street*. But you can’t use a Street object there since you don’t have a complete definition of Street at that point. You can only use pointers to Street in CrossStreet. (Additionally, you’re lacking storage allocation for m_acLoS, so even if you could use that type there, and if the assignment was legal, it would still be a bug).

    Depending on what you’re after, a std::vector<Street*> or std::list<Street*> or some other container could be what you’re looking for, instead of that incorrect member array. (But beware that you’re responsible for managing the lifetime of those pointers.)

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

Sidebar

Related Questions

#include<iostream> using namespace std; class Base{ private: int a; protected: Base(){}; virtual ~Base(){}; };
#include <iostream> using namespace std; typedef void (*pFun)(void); class A { private: int a;
#include<iostream> using namespace std; class A { private: const int a=9; public: void display()
#include <iostream> using namespace std; struct testarray{ int element; public: testarray(int a):element(a){} }; class
#include <iostream> using namespace std; class A{ int b; public: A(){ cout<<Constructor for class
#include<iostream> using namespace std; class Abc { public: int a; Abc() { cout<<Def cstr
#include <iostream> #include <cstring> #include <QString> using namespace std; class A { public: static
#include <iostream> using namespace std; class dummyA { int x; public: dummyA () {
#include <iostream> using namespace std; class Imp { public: int X(int) {return 50;} int
#include<iostream> using namespace std; class A { int a; int b; public: void eat()

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.