dimanche 4 décembre 2016

error xxx in yyy does not name a type

Compiling file error_xxx_does_not_name_a_type.cpp, why do I get error
error_xxx_does_not_name_a_type.cpp:5:28: error: ‘A’ in ‘struct std::pair<bool, int>’ does not name a type std::pair<bool, int> ::A::B::C::D::get_i()

// error_xxx_does_not_name_a_type.h
#pragma once
#include <utility>

namespace A{ namespace B{ namespace C{
struct D
{   
    std::pair<bool, int> get_i();
    std::pair<bool, int> get_j();
    std::pair<bool, int> get_k();
    int get_l();
};  
}}}

and

// error_xxx_does_not_name_a_type.cpp
#include "error_xxx_does_not_name_a_type.h"

#if 1 // gives me the error
std::pair<bool, int> ::A::B::C::D::get_i()
{ return {true, 10}; }
#endif
// But none of the below do
// missing ::
std::pair<bool, int> A::B::C::D::get_j()
{ return {true, 10}; }
// trailing return type
auto ::A::B::C::D::get_k()->
    std::pair<bool, int>
{ return {true, 10}; }
// return type int
int ::A::B::C::D::get_l()
{ return 10; }

I have compiled with g++ -Wall -Wextra -std=c++14 -c error_xxx_does_not_name_a_type.cpp and on g++ (Ubuntu 5.3.0-3ubuntu1~14.04) 5.3.0 20151204

Aucun commentaire:

Enregistrer un commentaire