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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:07:54+00:00 2026-06-11T23:07:54+00:00

I am trying to create a dynamic array of type ‘T’ that contains an

  • 0

I am trying to create a dynamic array of type ‘T’ that contains an array of type ‘X’. In order to access attributes of T from X, I tried creating a pointer in struct X that points to T. This is the code I have:

struct WireSeg; // Forward declaration

struct Track { // Type X in above description
    int trackNum;
    bool used;
    WireSeg* parentWireSeg;
};

struct WireSeg { // Type T in above description
    int xCoord; 
    int yCoord;
    char flag;
    char orientation;
    Track* track;
};

typedef WireSeg* WireSegPtr

int main (void) {
  WireSegPtr wireSeg;
  wireSeg = new WireSeg[5];
  for (int i =0; i<5; i++) {
    wireSeg[i].track = new Track[3];
    for (int j =0; j<3; j++) {
      wireSeg[i].track[j].parentWireSeg = wireSeg[i];
    }
  }
}

I get the compile error:

error: cannot convert ‘WireSeg’ to ‘WireSeg*’ in assignment

I don’t get it. parentWireSeg has been declared as a WireSeg type pointer and wireSeg[i] is also an element in the wireSeg array and is a pointer (isn’t it?).

I tried playing around with it and declared parentWireSeg to be of type WireSeg:

struct Track {
    int trackNum;
    bool used;
    bool flag;
    WireSeg parentWireSeg;
};

This gave me error:

‘struct Track’ has no member named ‘parentWireSeg’.

This makes no sense to me either since struct Track does have parentWireSeg as an element! Can someone please explain this? Am I not allowed to have a pointer in Track that points to WireSeg?

I can probably use inherited classes (can I?) for this but I would prefer if someone told me what is wrong with my method?

  • 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-11T23:07:55+00:00Added an answer on June 11, 2026 at 11:07 pm

    Try changing the line where you do the assignment to:

    wireSeg[i].track[j].parentWireSeg = &wireSeg[i];
    

    You see, wireSeg is of type WireSeg*, so when you dereference it by doing *wireSeg or wireSeg[0] or wireSeg[i], you get something that is of type WireSeg. If you want the address of the object instead of the object itself, so you can make a pointer, you need to add the address operator (&).

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

Sidebar

Related Questions

I am trying to create dynamic pages without creating new files and getting the
I am trying to create dynamic menus from the database using the following example
I am trying to create a dynamic hyperlink that depends on a value passed
In my code, I am trying to create a dynamic array with initArray function,
I'm trying to create a dynamic array of objects, similar to ArrayLists in Java.
Im trying to create a conditional statement that iterates through an array of nodes
I'm trying to create an associative array with dynamic data, and having some trouble.
I'm trying to create a dynamic memory. The size of the array is determine
I am trying to create a dynamic table that is being built based on
I'm trying to create dynamic multi level menus fetching the data from a MySQL

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.