Private members should be accessible from member functions of the same class. The following example works fine:
Code:
class classA
{
public:
void setMember(int m) { member = m; }
void someFunction(classA a);
private:
int member;
};
void classA::someFunction(classA a)
{
classA c;
c.setMember(a.member) // Access private member of same class
cout << c.member << endl;
}
int main()
{
classA a1;
a1.setMember(3);
classA a2;
a2.someFunction(a1);
return 0;
}
I'm having problems understanding your code though, for example, you've declared an array with no type (a[]), you haven't declared i anywhere and then you want to use "sameclass s3 = s1.a[];", but if you want to assign an element of that array to s3 then you need to use an index. Also, s1 doesn't appear to exist - in your function, you've passed objects of type sameclass called n1 and n2. If you could show us your code in its entirety and the exact error messages, that would help.
Also, you might want to use code tags, as they'll preserve your indentation if you're copying and pasting from a text editor.
As an aside, if you were trying to access a private member from another class, you would have to write a public accessor function, e.g.
Code:
class classA
{
public:
int getMember() { return member; }
private:
int member;
};
Code:
void classB::someFunc(classA a)
{
int x = a.getMember();
// Do stuff with x
}