我保證我已經找遍了很多年以找到解決方案,但無濟於事,但是我沒有經歷過C++,所以也許我只是不知道要搜索什麼。在構造函數中初始化矢量C++
我想最簡單的做法是首先向我展示我的錯誤代碼,以防它被識別。這有點堆,這就是爲什麼我無法弄清楚它是什麼問題。 (也就是我覺得它的東西,無論是出於我的理解,或者真的很煩人的錯誤,我做!)
g++ -Wall -pedantic -ansi -std=c++0x -g -c -o contacts.o contacts.cc
In file included from /usr/include/c++/4.6/vector:63:0,
from contacts.h:5,
from contacts.cc:2:
/usr/include/c++/4.6/bits/stl_construct.h: In function ‘void std::_Construct(_T1*,
_Args&& ...) [with _T1 = person, _Args = {}]’:
/usr/include/c++/4.6/bits/stl_uninitialized.h:481:3: instantiated from ‘static void
std::__uninitialized_default_n_1<_TrivialValueType>::__uninit_default_n(_ForwardIterator,
_Size) [with _ForwardIterator = person*, _Size = unsigned int, bool _TrivialValueType =
false]’
/usr/include/c++/4.6/bits/stl_uninitialized.h:529:7: instantiated from ‘void
std::__uninitialized_default_n(_ForwardIterator, _Size) [with _ForwardIterator =
person*, _Size = unsigned int]’
/usr/include/c++/4.6/bits/stl_uninitialized.h:604:7: instantiated from ‘void
std::__uninitialized_default_n_a(_ForwardIterator, _Size, std::allocator<_Tp>&) [with
_ForwardIterator = person*, _Size = unsigned int, _Tp = person]’
/usr/include/c++/4.6/bits/stl_vector.h:1134:2: instantiated from ‘void
std::vector<_Tp, _Alloc>::_M_default_initialize(std::vector<_Tp, _Alloc>::size_type)
[with _Tp = person, _Alloc = std::allocator<person>, std::vector<_Tp,
_Alloc>::size_type = unsigned int]’
/usr/include/c++/4.6/bits/stl_vector.h:239:9: instantiated from ‘std::vector<_Tp,
_Alloc>::vector(std::vector<_Tp, _Alloc>::size_type) [with _Tp = person, _Alloc =
std::allocator<person>, std::vector<_Tp, _Alloc>::size_type = unsigned int]’
contacts.cc:7:38: instantiated from here
編輯: 道歉,我不完全理解我在做什麼,但我希望這是你要求的。
Contacts.h:
#ifndef _CONTACTS_H
#define _CONTACTS_H
#include <iostream>
#include <vector>
#include "person.h"
class contacts{
private:
int element;
int count;
vector<person> pv;
public:
contacts();
};
#endif
和contacts.cc:
#include "contacts.h"
using namespace std;
contacts::contacts() : count(0), pv(0) {}
如果我有起碼這麼多在我的代碼(這兩個相關的文件)依然出現謝謝 -Ewan
後再現問題的最少代碼。縮小範圍。把它剪成最小的一塊。 –
是的,至少把你的聯繫人類標題放在這裏。 –
這個問題可能與人員課程有關;請張貼標題;你會想要爲'person'定義可訪問的默認和複製構造函數。 – Keith