Em có một project gồm 3 file là: header.h, source.cpp, main.cpp như sau:
//header.h
#ifndef header_h
#define header_h
class Test {
friend void B (int n);
};
#endif
//source.cpp
#include "header.h"
#include <iostream>
void B (int n) {
std :: cout << n;
}
//main.cpp
#include <iostream>
#include "header.h"
using namespace std;
int main () {
B(3);
return 0;
}
B là một hàm friend, nó được định nghĩa ở file source.cpp. Vấn đề em gặp phải ở đây là lúc gọi hàm B ở main.cpp thì nó bị lỗi: 'B' was not declared in this scope.
Vậy làm cách nào để sửa được lỗi này ạ ?