473,402 Members | 2,064 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Differences between C++ and Java with this-pointer


Hello,

I am trying to translate a C++ script to Java. Are there any differences
between the C++ this-pointer and the Java this-pointer?

Thank you

Flo
--
Posted via http://dbforums.com
Jul 19 '05 #1
5 15914
"Rasti" <me*********@dbforums.com> wrote...
I am trying to translate a C++ script to Java. Are there any differences
between the C++ this-pointer and the Java this-pointer?


In Java 'this' is NOT a pointer. There are no pointers in Java.

And, if you have questions on Java, try a Java newsgroup.

Victor

Jul 19 '05 #2

"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:28cqb.114745$e01.418754@attbi_s02...
"Rasti" <me*********@dbforums.com> wrote...
I am trying to translate a C++ script to Java. Are there any differences
between the C++ this-pointer and the Java this-pointer?


In Java 'this' is NOT a pointer. There are no pointers in Java.

And, if you have questions on Java, try a Java newsgroup.


Personally, I think that a question about the similarities and
differences between C++ and Java is on-topic for either C++ or Java
newsgroups. To answer the OP's question, in C++ 'this' is a pointer and in
Java 'this' is a reference, because Java doesn't have pointers. However,
the C++ 'this' pointer is rather strange, because it cannot be reassigned
and cannot be null. It probably should have been a reference. As I
understand it, the main reason it wasn't is because it was invented before
references were.

Joe Gottman

Jul 19 '05 #3
Joe Gottman wrote:


However,
the C++ 'this' pointer is rather strange, because it cannot be reassigned
and cannot be null.


void func(A& a);
A* aptr = 0;
func(*aptr);

I think you'll find that within func a's this pointer will
be null.
Jul 19 '05 #4
Victor Bazarov wrote:

"Rasti" <me*********@dbforums.com> wrote...
I am trying to translate a C++ script to Java. Are there any differences
between the C++ this-pointer and the Java this-pointer?


In Java 'this' is NOT a pointer. There are no pointers in Java.


There are no pointers, but there is a NullPointerException.

--

Pete Becker
Dinkumware, Ltd. (http://www.dinkumware.com)
Jul 19 '05 #5

"lilburne" <li******@godzilla.net> wrote in message
news:bo*************@ID-203936.news.uni-berlin.de...
Joe Gottman wrote:


However,
the C++ 'this' pointer is rather strange, because it cannot be reassigned and cannot be null.


void func(A& a);
A* aptr = 0;
func(*aptr);

I think you'll find that within func a's this pointer will
be null.


Derefencing a null pointer, as you do when you call func(*aptr) results
in undefined behavior. You might have a's this pointer null inside the
function call, or you might have a core dump before func is even called.

Joe Gottman
Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Chris Grimble | last post by:
I have a very simple applet that I am trying to make compatible with both Microsoft's JVM and Suns JVM in Internet Explorer. However, when I turn on the Sun JVM it works occasionally, but...
0
by: tim | last post by:
I've been given the task of trying to determine if some Java source code is the correct version of what is in production. Previous people took the source code and compiled it and then compared it...
0
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing...
13
by: Kieran | last post by:
I am designing a content management system and I want to make sure all pages entered into it's database by users are using valid HTML. I have designed the system to use HTML 4.01 Transitional...
4
by: MS | last post by:
Just a general question here re VBA. Can anyone explain the differences between "!" and "." when refering to a control? eg Me!TxtBox and Me.TxtBox. What is difference between "+" and "&"...
15
by: Paul Morrison | last post by:
Hi all, I need to come up with some differences between arrays in Java and C, I have searched Google and so far all I have found is the following: Arrays in Java are reference types with...
10
by: Brett | last post by:
Are there any books that mainly discuss differences between VB.NET and C#.NET? Possibly situations where you would specifically need/want to use one language over another. Thanks, Brett
4
by: Matt F | last post by:
Hey all, I'm a hobbyist programmer who usually codes in C++ or Java. I don't claim to be experts at either, and I'm not familiar with different types of variables, inheritance systems, etc. I've...
4
by: TastyWheat | last post by:
I've come upon two sources for DOM specification and I'm wondering if one is outdated or a different implementation or what. My first source is from W3C (using table as an example): ...
0
by: ccarter45 | last post by:
I need to compute the differences in color between 2 pictures. Also, I need to write a method that computes a useful difference color of two colors (where the colors and their difference will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.