I'm studying by myself C++. and I met some code that I can't understand. Some body help me, please.
The first point is:
student(void):student_no(number_student++){};
What's it mean in this code? I have MSDN, but I don't know what exactly it mean. I know student(void) is contructor function, but I don't understand: student_no(number_student++)
And secondly, I tried to overloading operator<< in ostream class, but I met some errors which I don't know how to fix.
And the last is I don't understand "const" mean in declear function:
student(const student& a_std);
This is my code
student.h
CODE
#include <iostream>
#include <vector>
#include <iterator>
using namespace std;
#using <mscorlib.dll>
class student
{
static int number_student;
int student_no;
public:
student(void):student_no(number_student++){};
student(const student& a_std);
void ShowID(void);
~student(void);
friend:
ostream& operator<<(ostream& out,const student& a_std)
{
return out << "Student ID: " << a_std.student_no;
}
};
student.cpp:
CODE
student::student(const student& a_std)
{
student_no = a_std.student_no;
cout << "Student iD: " << student_no << " calls copy operator" << endl;
}
void student::ShowID()
{
cout << "Student ID: " << student_no << endl;
}
//student::operator<<(ostream& out, const student& a_std)
//{
//
//}
student::~student(void)
{
}
And this is error messege: error C2275: 'std::ostream' : illegal use of this type as an expression
see declaration of 'std::ostream'
error C2059: syntax error : 'const'
This post has been edited by dinhvan5481: 18 Sep, 2006 - 10:26 PM