0

I wrote a small piece of code to test friend functions. It worked fine for methods that didn't belong to a specific class but when I tried to put it into a class all it can access is the public variables (just as any object would).

#include <iostream>
#include <conio.h>
using namespace std;


class something{
    int ip = 100;
public:
    int x = 100;
    void getIP();
    friend void cIP::changeIP(something);
};

void something::getIP(){
    cout << ip << endl;
}

class cIP{
public:
    int i;
    cIP();
    cIP(int nIP);
    something some;
    void changeIP(something s);
};
cIP::cIP(){
    i = 100;
}
cIP::cIP(int nIP){
    i = nIP;
}
void cIP::changeIP(something s){
    s.ip = i;
}

s.ip brings up the error member is inaccessible.

ryan651
  • 121
  • 1
  • 1
  • 3
  • It fails for similar reasons to those outlined in my answer to [a similar question](http://stackoverflow.com/questions/20954195/friend-methods-in-c-is-not-working/20954667#20954667). – juanchopanza Jan 08 '14 at 15:12
  • 1
    Thanks very much, really sorry I never spotted that question especially since it was only posted yesterday – ryan651 Jan 08 '14 at 15:19
  • You can close the question of this solves your problem – Louis93 Jan 08 '14 at 16:51

0 Answers0