DeamonX

I have been learning c++ so sooner or later i can learn to program with opengl. I have been learning how to program in c++ from 3dbuzz but I am a little confused. I don't quite understand pointers and I can't figure out how to override operators. Can someone show me example of how to override a operator

#include<iostream>

using namespace std;

main()

{

/*

I kind of know that *Two means it's

A operator but don't understand the &, I think

It is the memory address but not sure if i'm right */

char One = '1';

char *Two = &One;

*Two = '2';

/*

Is there a way to print a pointer out

The part I really dont get is what is Two with out the *

*/

cout << One << endl;

}



Re: Visual C++ Language Question. Need help.

einaros

DeamonX wrote:

Is there a way to print a pointer out

Two is a pointer to the char One. To print the value to which Two points, you need to do an indirection:

cout << *Two << endl;

How does your question relate to operator overloading






Re: Visual C++ Language Question. Need help.

pintu*

In you Question you are simple Assigning value to your pointer by Refrence,OverRide Doesn't Come in the Picture

:-

Two Concept
OverLoading:- Same Function Name with Different Signature.
OverRiding: Same Function Name with Same Signature


When you will read inheritance then these concept will Comes in Picture.So right now Don't Confuse with these things and Proceed Slowly.

Thanx





Re: Visual C++ Language Question. Need help.

Axe22

& = address (location) of data store

* = contents of the data store pointed at

 





Re: Visual C++ Language Question. Need help.

DeamonX

Thanks for showing me about the & and the *. Yea i'm at the part with inheritance but i dont get this:

//I get all the line inside the { } but i don't get line 1...............

//the ostream &operator << part

ostream &operator <<(ostream &stream, Point &p)
{
stream << p.getX() << "," <<p.getY() << "," << p.getZ();
return stream;
}





Re: Visual C++ Language Question. Need help.

einaros

That's an overloaded operator from the standard io library. Once you are familiarized with operators in general, it'll all make sense to you.

I suggest you acquire a good book, that'll save you some time :)






Re: Visual C++ Language Question. Need help.

Simple Samples

Yes pointers can be very confusing.

DeamonX wrote:
Is there a way to print a pointer out
Try:

cout << static_cast<void *>(Two) << endl;

DeamonX wrote:
The part I really dont get is what is Two with out the *
A pointer; also called an address.






Re: Visual C++ Language Question. Need help.

DeamonX

Thanks alot