I am getting the error while compiling the following simple C++ class program .
Error : ‘ptr_code’ undeclared (first use this function)
#include<iostream>
using namespace std;
class company
{
public:
int code;
int *ptr_code;
company(int i)
{
++count;
code=i ;
ptr_code = &code;
}
};
int main()
{
company c(10);
company *ptr_c = &c;
cout<<<<"\n";
cout<<"\nCompany codes : \n"<<ptr_c->*ptr_code<<"\n"<<ptr_c->code<<"\n";
system("pause");
return 0;
}
Please help me out in the same while the variable ptr_code is declared as integer pointer with public scope specifier , while the ptr_c->code is working fine.
Thanks in advance.
ptr_c->*ptr_codeshould be*ptr_c->ptr_code.ptr_c->*ptr_codewould be valid ifptr_codewas a variable of type pointer to company data member.