Hi I am trying to understand the scope of friend functions and I get a "not declared in scope" error. Here is my code:
//node.h
class Node{
public:
int id;
int a;
int b;
friend int add(int,int);
void itsMyLife(int);
Node();
};
//node.cpp
Node::Node(){
a=0;
b=0;
id=1;
}
void Node::itsMyLife(int x){
cout<<"In object "<<id<<" add gives "<<add(x,a)<<endl;
}
//routing.cpp
#include "node.h"
int add(int x, int y){
return x+y;
}
//main.cpp
#include "node.h"
int main(){
return 0;
}
I get the error "add not declared in this scope" in node.cpp. Why do I get this error when I have declared the function in the class scope? Any help will be appreciated. Thanks