Welcome to Dream.In.Code
Become a C++ Expert!

Join 137,402 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 2,108 people online right now. Registration is fast and FREE... Join Now!




Overloading operator.

 
Reply to this topicStart new topic

Overloading operator.

dinhvan5481
18 Sep, 2006 - 10:26 PM
Post #1

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 2


My Contributions
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
User is offlineProfile CardPM
+Quote Post

Xing
RE: Overloading Operator.
19 Sep, 2006 - 01:26 AM
Post #2

D.I.C Addict
Group Icon

Joined: 22 Jul, 2006
Posts: 723



Thanked: 2 times
Dream Kudos: 1575
My Contributions
Read about Initialization Lists

This post has been edited by Xing: 19 Sep, 2006 - 01:26 AM
User is offlineProfile CardPM
+Quote Post

dinhvan5481
RE: Overloading Operator.
19 Sep, 2006 - 06:57 AM
Post #3

New D.I.C Head
*

Joined: 16 Sep, 2006
Posts: 2


My Contributions
QUOTE(Xing @ 19 Sep, 2006 - 02:26 AM) *


Thank you Xing. You gived me a very useful website, I got a lot of info in there.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 12/5/08 03:11AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month