473,834 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 15945
"Rasti" <me*********@db forums.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.********@com Acast.net> wrote in message
news:28cqb.1147 45$e01.418754@a ttbi_s02...
"Rasti" <me*********@db forums.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*********@db forums.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 NullPointerExce ption.

--

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

"lilburne" <li******@godzi lla.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
5844
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 frustratingly on most occasions I get the following error messages: In the status bar: "Applet <name> notinited" And when I investigate further in the console I get the following output:
0
2595
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 to the class they extracted from the production ear file. There were slight differences but they said they were 99% the same. I'm not sure how they reached that conclusion. My question is, is it possible that the production classes were compiled...
0
1909
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 build release comparisons (I use a script to generate a main page showing all the files that were changed in a build with hyperlinks to side by side differences for each of those files). I also find it useful for generating HTML test reports to...
13
9640
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 throughout, however the php powered html checker I have only caters for HTML 4.01 Strict. If possible I need to know the complete differences between Strict and Transitional so I can go through the php script and correctly set it up to properly...
4
3714
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 "&" when working with strings. eg MyStr = "I have " & MyNumber & " apples." and MyStr = "I have " + MyNumber + " apples."
15
7020
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 automatic allocation of memory. In C, arrays are groups of variables of the same type in adjacent memory. Allocation for dynamic arrays is handled by the programmer. This is an 8 mark question in an old exam paper, so I am assuming there are
10
1475
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
4843
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 decided to play around with C# and .NET 2.0 a little bit, but I'm still not completely certain about the differences between C++ and C#. All I know is that there are some limitations that aren't on C++ (which is probably a good thing... I think...
4
1396
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): http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-64060425 My other source is from Sun Microsystems: http://java.sun.com/j2se/1.5.0/docs/guide/plugin/dom/org/w3c/dom/html/HTMLTableElement.html
0
1742
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 represented as single int's). The formula you should use for colordiff, the difference color between color1 and color2, with color1 = (R1, G1, B1) and color2 = (R2, G2, B2) is as follows: colordiff = (Rdiff, Gdiff, Bdiff) where Rdiff = |R1-R2| Gdiff =...
0
9644
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10793
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10509
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10547
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10219
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7757
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5626
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3977
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3081
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.