First timer trying to understand constructors

I have never completed a C or VB or C++ programming course.

So I am reading a C++ tutorial, which shows me this introducing a constructor:

The constructor assigns the message Course Not Changed to the instance variable status. This is the default status for each instance of the class. The value of the status instance variable is changed from the default value to the message Course Dropped by the dropCourse method.

class MyJavaApplication {
public static void main (String args[]) {
RegistrationForm regForm = new RegistrationForm();
regForm.dropCourse(CS102,1234);
System.out.println("Status: " + regForm.status);
}
}
class RegistrationForm {
String status;


void RegistrationForm () {
status = "Course Not Changed.";
}
void dropCourse(int courseNumber, int studentNumber)
{status = "Course: "+ courseNumber + " is dropped for
student: " + studentNumber;
}
}


I am thinking the constructor is this line:

void RegistrationForm () {
status = "Course Not Changed.";
}

Am I correct?
*cringes*Java, we meet again *slowly draws sword*

No, a constructor goes by the EXACT same identifier as the class and CANNOT have a return type.

1
2
3
4
5
class immaClass
{
    immaClass (); //imma constructer rilly, but don't a blow mah cuver dood
    immaClass (int a, int b); // This is an overloaded constructor
}


*stabs Java in the black hole that it it's soul* Die you * expletive content*

May I ask why you used Java when talking about a C++ tutorial?
The example above is a copy and paste right from Chapter 2 of the C++ tutorial I have...so it looks like there may be a typo in the example they provided, which doesn't help with learning the subject.

Thanks.
The example above is a copy and paste right from Chapter 2 of the C++ tutorial I have


Haw. Your "C++" tutorial is teaching you Java.

If you're interested in learning Java, I guess that's fine. But if you want to learn C++, I recommend finding a tutorial that actually shows C++ code.
I answered a similar thread (about constructors) not too long ago.
http://www.cplusplus.com/forum/general/52443/#msg284466

Also, there is the tutorial on this site:
http://www.cplusplus.com/doc/tutorial/classes/

I hope this helps.
Topic archived. No new replies allowed.