안녕하세요 나는 내가이hpp에서 벡터를 선언하는 방법은 무엇입니까?
std::vector<double> a(0);
처럼하지만 내 파일이 작동하지 않습니다 할 가지고 std::vector
선언 알고있다.
MAIN.CPP :
#include "test.hpp"
int main()
{
Test test;
return EXIT_SUCCESS;
}
test.hpp : 여기 내 코드입니다
#ifndef DEF_TEST
#define DEF_TEST
#include <iostream>
#include <vector>
class Test
{
public:
Test();
private:
std::vector<double> a(0);
};
#endif
이것은 Test.cpp에 있습니다 :
#include "test.hpp"
Test::Test()
{
a.push_back(2.3);
std::cout << a[0] << std::endl;
}
그리고 컴파일러는 나에게 말했다 :
In file included from main.cpp:1:0:
test.hpp:11:23: error: expected identifier before numeric constant
std::vector<double> a(0);
^
test.hpp:11:23: error: expected ‘,’ or ‘...’ before numeric constant
In file included from test.cpp:1:0:
test.hpp:11:23: error: expected identifier before numeric constant
std::vector<double> a(0);
^
test.hpp:11:23: error: expected ‘,’ or ‘...’ before numeric constant
test.cpp: In constructor ‘Test::Test()’:
test.cpp:5:1: error: ‘((Test*)this)->Test::a’ does not have class type
a.push_back(2.3);
^
test.cpp:6:17: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
std::cout << a[0] << std::endl;
도움 주셔서 감사합니다.