Cannot acces private member in friend operator.

Hello :)
I know I failed somewhere,but I can't understand where is the mistake.Why can't i accses 'num' ?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
using namespace std;


class wInt {
private:
	int num;
public:
	friend void operator+(const wInt&,const wInt&);
};



inline void operator+(const wInt& w1,const wInt w2){
	w1.num; //here
}


error at line 15,error C2248: 'wInt::num' : cannot access private member declared in class 'wInt'
Yes,i know that line 15 has no purpose,but it's enough to get the error.
Thanks in advance :)
If you want access to the private member variables you either need to make this a member function or a friend. Also you have two const parameters, what is the purpose of the function? Remember if a parameter is const you can't change that parameter.


The function is a friend,look at the declaration.This is a small part of a program,I wrote the shortest form I could,so the function has no purpose here.
inline void operator+(const wInt& w1,const wInt w2){
this should be
inline void operator+(const wInt& w1,const wInt& w2){
I can't believe this was the mistake...sorry guys for this dumb question,I'm very tired...
And thanks again Cubbi ! :)
Last edited on
Topic archived. No new replies allowed.