// 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
Recommended Answers
Jump to PostYou are attempting to set a pointer to a pointer to itself. That makes no sense at all, something like saying "you are your own father".
Note: main must be declared to return an int. c++ does not allow declaring functions without a return type.
You need to do something …
Jump to PostEdit: Oop. Didn't notice Jason's post.
Jump to PostWell Thanks for reply. But that is not the correct solution because the deseired result is not achieved.
Humm -- I answered the question you asked. Don't blaim me if your program doesn't work right after correcting the problem you asked about.
All 12 Replies
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.