0

我保证我已经环顾四周寻找解决方案,但无济于事,但是我没有 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

编辑:抱歉,我不完全理解我在做什么,但我希望这是你所要求的。如果我的代码中至少有这么多(两个相关文件),错误仍然会出现:

联系人.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) {}

谢谢-伊万

4

1 回答 1

1

你为什么要传递0给 std::vector<> 构造函数?这听起来与您所写的效果相同:

contacts::contacts() : count(0) {}

于 2012-12-06T01:28:03.010 回答