Когда я компилирую мой класс, я получаю серьезную ошибку:Ошибка C2558 - конструктор копирования
C2558 no copy constructor available or copy constructor is declared 'explicit'
Но мой конструктор копирования не является ни частной, ни явным!
Заголовок:
#include "Csequence.h"
using namespace std;
class Cnoeud
{
private:
Cnoeud *oNOEpere;
vector<Cnoeud> oNOEfils;
Csequence oNOEsequence;
bool oNOEStatut;
public:
// Liste des constructeurs
Cnoeud();
Cnoeud(Cnoeud &);
~Cnoeud(){}
// Liste des accesseurs et des modificateurs
Cnoeud * NOEAfficherpere(){ return oNOEpere;}
vector<Cnoeud> NOEAfficherfils() {return oNOEfils;}
Csequence NOEAffichersequence() {return oNOEsequence;}
bool NOEAfficherstatut() { return oNOEStatut;}
void NOEModifierpere(Cnoeud oNOEp){ *oNOEpere=oNOEp;}
void NOEModifierfils(vector<Cnoeud>);
void NOEModifiersequence(Csequence oNOEs){oNOEsequence = oNOEs;}
void NOEModifierstatut(bool {oNOEStatut = b;}
// Liste des fonctions membres
void NOEViderfils(){ oNOEfils.clear();}
// Surcharge de l'opérateur d'affectation
Cnoeud & operator=(Cnoeud &) ;
};
Источник:
Cnoeud.cpp
#include <iostream>
#include <vector>
#include "Cnoeud.h"
using namespace std;
Cnoeud::Cnoeud()
{
oNOEStatut= 0;
oNOEsequence.SEQInitialiserdatesfin();
oNOEsequence.SEQInitialisersequence();
oNOEpere = NULL;
}
Cnoeud::Cnoeud(Cnoeud & oNOE)
{
oNOEStatut= oNOE.oNOEStatut;
oNOEsequence = oNOE.NOEAffichersequence();
oNOEpere = oNOE.NOEAfficherpere();
oNOEfils.clear();
vector<Cnoeud>::iterator it;
for(it=oNOE.NOEAfficherfils().begin();it!=oNOE.NOEAfficherfils().end();it++)
{
oNOEfils.push_back(*it);
}
}
Как-то ваш код потерял все отступы при копировании с его IDE. Было бы намного легче читать, если бы вы могли исправить это. Там также должно быть что-то отсутствует. '# endif' просто застрял там случайно, без' # if'. –
Чтобы иметь возможность использовать функции объявленного объекта const, его функции должны быть объявлены как const, а компилятор не будет знать, будут ли функции изменять объект const. Я рекомендую прочитать Const Correctness [link] (http: // www.parashift.com/c++-faq-lite/const-correctness.html) на сайте C++ FAQ. – Zoomulator