| description | title | ms.date | f1_keywords | helpviewer_keywords | ms.assetid |
|---|---|---|---|---|---|
|
Learn more about: Compiler Error C2429 |
Compiler Error C2429 |
11/16/2017 |
C2429 |
C2429 |
57ff6df9-5cf1-49f3-8bd8-4e550dfd65a0 |
Compiler Error C2429
‘language feature‘ requires compiler flag ‘compiler option‘
The language feature requires a specific compiler option for support.
The error C2429: language feature ‘nested-namespace-definition’ requires compiler flag ‘/std:c++17’ is generated if you try to define a compound namespace, a namespace that contains one or more scope-nested namespace names, starting in Visual Studio 2015 Update 5. (In Visual Studio 2017 version 15.3, the /std:c++latest switch is required.) Compound namespace definitions are not allowed in C++ prior to C++17. The compiler supports compound namespace definitions when the /std:c++17 compiler option is specified:
// C2429a.cpp namespace a::b { int i; } // C2429 starting in Visual Studio 2015 Update 3. // Use /std:c++17 to fix, or do this: // namespace a { namespace b { int i; }} int main() { a::b::i = 2; }
Using MS Visual studio I created a solution containing 2 projects called MainProject and CalcProject
MainProject is a console app that references CalcProject and only contains main() in a .cpp file
CalProject is a library and contains a few header files with the following:
Nml.h contains the following:
#include <cstdint>
#include " Ftr.h"
#include " Mtr.h"
namespace CalcProject::measure
{
class Mtr;
class Ftr;
class Nml
{
public:
...
Ftr.h contains the following:
#include <cstdint>
#include " Mtr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Mtr;
class Nml;
class Ftr
{
...
Mtr.h contains the following:
#include " Ftr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Ftr;
class Nml;
class Mtr
{
...
MainProject.cpp contains the following:
#include "pch.h"
#include "Ftr.h"
#include <iostream>
#include <string>
using namespace CalcProject::measure;
int main()
{
When I build the solution I receive the following error
Error C2429 language feature ‘nested-namespace-definition’ requires compiler flag ‘/std:c++17’ MainProject
I tried to resolve this by specifying /std:c++17 in the C++ Language standard in the project properties but the error persists.
How can I fix this? Please advise on a possible solution. I am a beginner and this is my first C++ project using multiple header and cpp files to create a library.
Using MS Visual studio I created a solution containing 2 projects called MainProject and CalcProject
MainProject is a console app that references CalcProject and only contains main() in a .cpp file
CalProject is a library and contains a few header files with the following:
Nml.h contains the following:
#include <cstdint>
#include " Ftr.h"
#include " Mtr.h"
namespace CalcProject::measure
{
class Mtr;
class Ftr;
class Nml
{
public:
...
Ftr.h contains the following:
#include <cstdint>
#include " Mtr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Mtr;
class Nml;
class Ftr
{
...
Mtr.h contains the following:
#include " Ftr.h"
#include " Nml.h"
namespace CalcProject::measure
{
class Ftr;
class Nml;
class Mtr
{
...
MainProject.cpp contains the following:
#include "pch.h"
#include "Ftr.h"
#include <iostream>
#include <string>
using namespace CalcProject::measure;
int main()
{
When I build the solution I receive the following error
Error C2429 language feature ‘nested-namespace-definition’ requires compiler flag ‘/std:c++17’ MainProject
I tried to resolve this by specifying /std:c++17 in the C++ Language standard in the project properties but the error persists.
How can I fix this? Please advise on a possible solution. I am a beginner and this is my first C++ project using multiple header and cpp files to create a library.
I aware that someone asked similar question but what I have seen is different error when I try to use c++17 Structure Binding in my code (e.g. for (auto [i, it] = std::tuple{ 0, nodes.begin() }; i < size; i++)), I have already set to use ISO C++17 Standard (/std:c++17) in project properties and checked compiler version.
Ref: Using c++17 ‘structured bindings’ feature in visual studio 2017
Compiler complained
Error C2429 language feature ‘structured bindings’ requires compiler flag ‘/std:c++17’
My Code
TreeNode* ConstructBinaryTree(const int* const intChain, size_t size)
{
std::list<TreeNode*> nodes;
for (auto [i, it] = std::tuple{ 0, nodes.begin() }; i < size; i++)
{
TreeNode* curr = (it != nodes.end())? *it : nullptr;
TreeNode* toBeAssiged = new TreeNode(intChain[i]);
nodes.push_back(toBeAssiged);
if (curr)
{
if (curr->left)
{
curr->right = toBeAssiged;
it++;
}
else
{
curr->left = toBeAssiged;
}
}
}
return (nodes.size() == 0)? nullptr : *nodes.begin();
}
According to https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=vs-2019
Structure binding should be supported after VS 2017 15.3 17
My compiler version

I aware that someone asked similar question but what I have seen is different error when I try to use c++17 Structure Binding in my code (e.g. for (auto [i, it] = std::tuple{ 0, nodes.begin() }; i < size; i++)), I have already set to use ISO C++17 Standard (/std:c++17) in project properties and checked compiler version.
Ref: Using c++17 ‘structured bindings’ feature in visual studio 2017
Compiler complained
Error C2429 language feature ‘structured bindings’ requires compiler flag ‘/std:c++17’
My Code
TreeNode* ConstructBinaryTree(const int* const intChain, size_t size)
{
std::list<TreeNode*> nodes;
for (auto [i, it] = std::tuple{ 0, nodes.begin() }; i < size; i++)
{
TreeNode* curr = (it != nodes.end())? *it : nullptr;
TreeNode* toBeAssiged = new TreeNode(intChain[i]);
nodes.push_back(toBeAssiged);
if (curr)
{
if (curr->left)
{
curr->right = toBeAssiged;
it++;
}
else
{
curr->left = toBeAssiged;
}
}
}
return (nodes.size() == 0)? nullptr : *nodes.begin();
}
According to https://learn.microsoft.com/en-us/cpp/overview/visual-cpp-language-conformance?view=vs-2019
Structure binding should be supported after VS 2017 15.3 17
My compiler version
