Nobody is talking about name and str. What MikeyBoy is talking about is p and pay which he has clearly put in bold so I don't know why are you bringing name and *str up?
And the fact of the matter is they are differrent types.
pay is an int
p is a pointer to int
This clearly indicated here:
F:\c++projects\thispointer\pointerthis.cpp|13|error: invalid conversion from 'int*' to 'int' [-fpermissive]
And you have multiple such errors too. Hint: You actually don't want p to be a pointer at all.
I also suggest the OP to stop treating compilation errors as
my code doesn't work
and instead view them as useful hints on where things might have gone wrong.
For this cout.write(this->*pay);
i get this
F:\c++projects\thispointer\pointerthis.cpp|19|error: '((salesman*)this)->salesman::pay' cannot be used as a member pointer, since it is of type 'int*'|
how do i get around this one?I tried float but similar error comes
i thought if pay and *p are different then so must be name and *str.
But pay and *p are the same type.
pay and p are different types.
I have a feeling that the real problem is that you don't really understand pointers, nor the syntax for declaring and using them. I'd recommend going back to your textbook, and getting a clearer understanding of that chapter.
my textbook is really bad for pointers so are the online resources(too advanced).Do you know any study material online for just the basics of pointers?Unfortunately i am not able to devote time to computer science because of my main subjects physics chemistry maths.
This tutorial was written for somebody who has never heard about pointers in their life.
If this is too advanced for you then you're just not trying hard enough.