• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

cannot be applied to

 
Ranch Hand
Posts: 102
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting an error on line 243 "setLeft(TreeNode) in TreeNode cannot be applied to (ExprTree)" From what I understand What is sent in the parameter for setLeft method should be of type TreeNode so am I incorrect in thinking that I can call the constructor from within the same class to create a new node of type TreeNode?
 
Sheriff
Posts: 28322
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dustin Schreader wrote:I'm getting an error on line 243 "setLeft(TreeNode) in TreeNode cannot be applied to (ExprTree)" From what I understand What is sent in the parameter for setLeft method should be of type TreeNode so am I incorrect in thinking that I can call the constructor from within the same class to create a new node of type TreeNode?



Well, yes. You don't need me to tell you that an ExprTree isn't a TreeNode -- the compiler has already told you that. So yes, you're incorrect, calling the ExprTree constructor doesn't result in an object of type TreeNode. It results in an ExprTree object, of course.
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Dustin

Its hard to know the complete logic of your program with this code, it would be better if you can post the code of setLeft(TreeNode) method
or may be an explanation of your Treenode class.

what i understand from this code is that you should pass the ROOT object that you are creating to the setLeft() method instead of Exptree object.

Regards
Anurag Malaviya
 
Dustin Schreader
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was supposed to put a ExprTreeNode instead and now it works... It must be getting late... Thank you for the direction because it seemed to help.
 
Ranch Hand
Posts: 287
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if ExprTreeNode extends TreeNode, then you won't get that compilation error. As ExprTreeNode IS - A TreeNode now.
 
Dustin Schreader
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suppose I'm wondering if this is really the proper way to be doing this. ExprTreeNode is the ADT and the TreeNode is my interface. We're just learning trees and interfaces, so I guess what I should say is, should I be using ExprTreeNode's constructor or is it more correct to access the constructor through the interface TreeNode somehow. This is part of a lab and the code for the interface was already given so i'm not sure if I should be modifying it at all. Here is the interface.
 
Please do not shoot the fish in this barrel. But you can shoot at this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic