Aby poćwiczyć przyjaźń klasy z funkcją stworzyłem taki przykładowy kod:
#include
#include
using namespace std;
class CReferencja
{
private:
string strNapis;
public:
CReferencja() { strNapis = "Konstruktor domyslny"; }
friend void funkcja(CReferencja&);
};
void funkcja(CReferencja& ref)
{
ref.strNapis = "Funkcja zaprzyjazniona :)";
cout << ref.strNapis << endl << endl;
system("pause");
}
int main()
{
funkcja;
system("pause");
return 0;
}
Lecz mam problem z wywołaniem funkcji w main. Nie wiem z jakim parametrem wywołać funkcje
int main()
{
funkcja(CReferencja& ref);
// ...
}
Wyświetla błąd: error C2065: ‘ref’ : undeclared identifier oraz error C2275: ‘CReferencja’ : illegal use of this type as an expression.