| | |
Error - Going from Java to C++
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
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 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++.
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?•
•
Join Date: Jan 2008
Posts: 3,828
Reputation:
Solved Threads: 501
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:
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
| Thread Tools | Search this Thread |
api array arrays based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete deploy developer dll download dynamiccharacterarray email encryption error file forms fstream function functions game generator getline givemetehcodez graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template text text-file tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






