Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

'this' pointer

Suyash SinghSuyash Singh Member Posts: 1

In my program
#include
#include<string.h>
using namespace std;
class salesman
{
private:
char name[80];
int pay;
public:
salesman(char *str,int p)
{
strcpy(name,str);
pay=&p;
}
void outdata()
{
cout.write(this->name,80);
cout<<" has salary ";
cout.write(this->
pay);
}
};
int main()
{
salesman s1("Raman",4000),s2("Rita",2000);
s1.outdata();
s2.outdata();
}
for the line cout.write(this->*pay);
i get error 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'|

Can you tell me how to get around this one?

Sign In or Register to comment.