Error - Going from Java to C++

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Feb 2009
Posts: 19
Reputation: icu222much is an unknown quantity at this point 
Solved Threads: 0
icu222much icu222much is offline Offline
Newbie Poster

Error - Going from Java to C++

 
0
  #1
29 Days Ago
I have created a linked list in Java, and now I am trying to convert my program to C++.
When I try to compile, it gives me the error saying that 'next' uses 'CarNode' which is being defined. I am wondering if there is any way around this?

Java:
  1. public class CarNode {
  2. public Car carObject;
  3. public CarNode next;
  4.  
  5. public CarNode (Car newCar, CarNode newNext) {
  6. carObject = newCar;
  7. next = newNext;
  8. }
  9. }


C++:
  1. class CarNode: public Car {
  2. public:
  3. Car carObject;
  4. CarNode next;
  5.  
  6. CarNode(Car newCar, CarNode newNext) {
  7. carObject = newCar;
  8. next = newNext;
  9. }
  10. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 1,280
Reputation: firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice firstPerson is just really nice 
Solved Threads: 157
firstPerson's Avatar
firstPerson firstPerson is offline Offline
Nearly a Posting Virtuoso
 
0
  #2
29 Days Ago
I am a little doubtful about your code. Why does CarNode inherit from
Car and it also composes it ?

Note that in c++ objects is by default passed by value and Not passed by
reference. You may wan't to read about pointers and reference in c++.
1) What word becomes shorter if you add a letter to it? 
      [ Solved by : niek_e, Paul Thompson, SgtMe]
2) What does this sequence  equal to :  (.5u - .5a)(.5u-.5b)(.5u-.5c) ...
      [*solved by : murtan]
3) What is the 123456789 prime numer?
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 19
Reputation: icu222much is an unknown quantity at this point 
Solved Threads: 0
icu222much icu222much is offline Offline
Newbie Poster
 
0
  #3
29 Days Ago
thank you.
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 3,828
Reputation: VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute VernonDozier has a reputation beyond repute 
Solved Threads: 501
Featured Poster
VernonDozier VernonDozier is offline Offline
Senior Poster
 
0
  #4
29 Days Ago
Yeah, I don't see the word "extends" in your Java code, so I'm doubtful of the inheritance. firstPerson is right regarding pointers and pass-by-value. I'd have to see the overall set-up, but you're probably looking for something ike:

  1. class CarNode/*: public Car */
  2. {
  3. public:
  4. Car* carObject;
  5. CarNode* next;
  6.  
  7. CarNode(Car* newCar, CarNode* newNext)
  8. {
  9. carObject = newCar;
  10. next = newNext;
  11. }
  12. };

Note that I commented the inheritance out. Also, both in C++ and Java, consider, making the data members private and using getter and setter methods.
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC