// In this program:
when i compile this program, the complier shows error in the main section(I have mention this error
in main section) that is "can not convert sample to sample in assignment".
this error is occuring only when i try to access private members of class through pointer object.
I am unable to solve this. please can some one help to solve it.
note: solve it only by pointer variable
#include<iostream>
#include<conio.h>
using namespace std;
class sample
{
private:
int a,b;
public:
void setdata(int x, int y)
{
x=a;
y=b;
}
void print()
{
cout<<a+b;
}
};
main()
{
sample *e;
e=&e; //here compiler generates error "can't convert sample to sample in assignment"
e->setdata(5,6);
e->print();
getch();
}
irtza 0 Newbie Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
irtza 0 Newbie Poster
tinstaafl 1,176 Posting Maven
JasonHippy 739 Practically a Master Poster
Moschops 683 Practically a Master Poster Featured Poster
irtza 0 Newbie Poster
Moschops 683 Practically a Master Poster Featured Poster
Ancient Dragon 5,243 Achieved Level 70 Team Colleague Featured Poster
JasonHippy 739 Practically a Master Poster
irtza 0 Newbie Poster
samiz4j 0 Newbie Poster
samiz4j 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.