| | |
Error - Going from Java to C++
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Feb 2009
Posts: 19
Reputation:
Solved Threads: 0
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:
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:
C++ Syntax (Toggle Plain Text)
public class CarNode { public Car carObject; public CarNode next; public CarNode (Car newCar, CarNode newNext) { carObject = newCar; next = newNext; } }
C++:
C++ Syntax (Toggle Plain Text)
class CarNode: public Car { public: Car carObject; CarNode next; CarNode(Car newCar, CarNode newNext) { carObject = newCar; next = newNext; } }
0
#2 Nov 6th, 2009
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++.
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) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
•
•
Join Date: Jan 2008
Posts: 3,844
Reputation:
Solved Threads: 503
0
#4 Nov 7th, 2009
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:
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.
C++ Syntax (Toggle Plain Text)
class CarNode/*: public Car */ { public: Car* carObject; CarNode* next; CarNode(Car* newCar, CarNode* newNext) { carObject = newCar; next = newNext; } };
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.
![]() |
Similar Threads
- Cant Solve this Java Error (Java)
- Illegal Start of type error (Java)
- I got error while i am trying to use java generic classes in jsp (JSP)
- error :java.lang.NullPointerException in searchuser.jsp page (JSP)
- Need help with error Exception in thread "main" java.lang.Nu (Java)
- can someone help java error ( ')' expected ) (Java)
- Java Error (Java)
- Error java.sql.SQLException: [Microsoft][ODBC Driver Manager] Driver's SQLAllocHandle (Java)
- java.lang.NoSuchMethod error at runtrime (Java)
- SSL LADP error with Java (Java)
Other Threads in the C++ Forum
- Previous Thread: Recursion Help!
- Next Thread: general protection error
Views: 242 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C++
6 add api array arrays beginner binary bitmap c++ c/c++ calculator char class classes code compile compiler console conversion convert count data delete desktop directshow dll encryption error file forms fstream function functions game getline givemetehcodez google graph homeworkhelper iamthwee ifstream input int integer java lazy lib linkedlist linux loop looping loops map math matrix memory microsoft newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort string strings struct studio system template templates test text tree unix url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






