How Intel® C++ Compiler Handles Functions declared inside functions

Reference number:

In accordance with the C++ language specification, if a function declaration is encountered within a function definition, the function referenced is taken to be another member of the namespace of the containing function; regardless of whether the containing function definition is lexically within a namespace definition. The Microsoft Visual C++* compiler takes the referenced function to be a global function (not in any namespace). Functions declared in global or namespace scopes are interpreted the same way by both the Intel® C++ Compiler and the Microsoft Visual C++* compiler.

Following code illustrates the difference:--

using namespace std;

namespace sf1 {
void f1(){

cout<<"entered into f1" << endl;
void f2();


int main(){

return 0;


#include <iostream>
using namespace std;
void f2(){cout<<"entered f2" << endl;}

Using Microsoft Visual C++* compiler , output is:--
(cl decl.cpp f2.cpp)

entered into f1
entered f2
Press any key to continue . . .

Using Intel® C++ Compiler, error is:--
(icl decl.cpp f2.cpp)

: error LNK2019: unresolved external symbol "void __cdecl sf1::f2(void)" (?f2@sf1@@YAXXZ) referenced in function "void __cdecl sf1::f1(void)" (?f1@sf1@@YAXXZ)

This issue has been fixed in the latest 11.1 compiler update
Для получения подробной информации о возможностях оптимизации компилятора обратитесь к нашему Уведомлению об оптимизации.
Возможность комментирования русскоязычного контента была отключена. Узнать подробнее.