The following simple application demonstrates the compile error:
My class declaration: MyClass.h
#pragma once
class MyClass
{
friend int MyCalc();
public:
};
class definition: MyClass.cpp
#include "stdafx.h"
#include "MyClass.h"
int MyCalc()
{
return 1 + 2;
}
The main function: ConsoleApplication1.cpp
#include "stdafx.h"
#include "MyClass.h"
#include <iostream>
int main()
{
std::cout << MyCalc();//"Identifier MyCalc is undefined" in Visual Studio 2019, but not in 2015
return 0;
}
I'm guessing the updated c++ version has made this more restrictive. So will I have to add a declaration of the function outside of the class everywhere I have a friend function declared, like so:
class MyClass
{
friend int MyCalc();
public:
};
int MyCalc();