2
죄송합니다. 더 나은 제목을 찾을 수 없습니다.템플릿 개체의 컴파일 순서는 어떻게됩니까?
#include <vector>
void foo();
int main() {
foo();
return 0;
}
void foo(){
struct point {
double x, y;
};
std::vector<point> p;
}
// g++ output:
a.cpp: In function ‘void foo()’:
a.cpp:14: error: template argument for ‘template<class _Tp> class std::allocator’ uses local type ‘foo()::point’
a.cpp:14: error: trying to instantiate ‘template<class _Tp> class std::allocator’
a.cpp:14: error: template argument 2 is invalid
a.cpp:14: error: invalid type in declaration before ‘;’ token
내가 두 번째 방법에 어떤 문제가 있는지 알고 싶어 컴파일러는 다음에 대해 불평 반면
#include <vector>
void foo();
int main() {
foo();
return 0;
}
namespace{
struct point {
double x, y;
};
}
void foo(){
std::vector<point> p;
}
다음 컴파일 미세 내가 눈치 기본적으로 무엇 이었습니까? 새 std::vector<point>
개체를 만들 때 struct point
이 완전히 정의되어 있지 않습니까?
나를 이길 :( –