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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T14:10:23+00:00 2026-05-30T14:10:23+00:00

Im working with tree. Every node have object with Tree * values. I read

  • 0

Im working with tree. Every node have object with Tree * values. I read data which looks like:

1
2
2
...

It means, put 1 as child of 0, put 2 as child of 1, put 3 as child o 2. In regular form: put x as child of i-1 where i is number of row.

I decided to make tree, looks like:

class Tree {
public:
    int value;
    stack <Tree*> children;

    Tree ();
    Tree (int x) {value = x;}
    void wypisz();
};

So now when i read input i have something to do like this (but it doesn’t work):

int n,x;
scanf("%d",&n);
Tree **tab;
tab = (Tree **) malloc(sizeof(Tree*)*n);
Tree *n = 0;
tab[0] = new Tree(0);
for(int i=1;i<n;++i) {
    scanf("%d",&x);
    n = new Tree(x);
    tab[i] = n;
    tab[i-1]->children.push(n);
}
delete n;

So i need to n = new Tree(x); be a pointer to new object of tree, and add this pointer
to tab at [i] place and add this pointer to children of tab[i-1] element. What’s wrong with
this code?
Those lines doesn’t compile:

n = new Tree(x);
tab[i] = n;

With error:

  1. line: Value ot type “Tree *” cannot be assigned to an entity of type “int”.
  2. line: Value ot type “int” cannot be assigned to an entity of type “Tree *”.
  • 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-30T14:10:24+00:00Added an answer on May 30, 2026 at 2:10 pm

    First you declare n as an int. Later you declare n as a Tree*.

    These two declarations conflict, since they try to declare the same variable with two different types. To avoid the conflict, use two different variable names.

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

Sidebar

Related Questions

I have edits to my working tree which I would like to continue working
I'm working on building a tree structure in MySQL and have been experimenting with
I'm working on UVa #112 Tree Summing . I have what I think should
I am working on a server application which receives data over a TCP socket
I am working with mysql and php and have a Parent Child table created
I am working on treeview control. i would like to have insert a feature
I have a working tree model derived from QAbstractItemModel and I wish to filter
How do I delete untracked local files from the current working tree?
I accidentially discard my changes on files in my local working tree via git
I'm working with a tree structure in MySQL that is respresented using the nested

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.