I wrote code (C ++, visual studio 2010) that has a vector, even if I declare that const const is declared, but still shows that copy const is not declared
Here is the code
#include<iostream> #include<vector> using namespace std; class A { public: A() { cout << "Default A is acting" << endl ; } A(A &a) { cout << "Copy Constructor of A is acting" << endl ; } }; int main() { A a; A b=a; vector<A> nothing; nothing.push_back(a); int n; cin >> n; }
The error I received is
Error 1 error C2558: class 'A': no โโcopy constructor is available or the copy constructor is declared "explicit" c: \ program files \ microsoft visual studio 10.0 \ vc \ include \ xmemory 48 1 delete
Someone please help me
The copy constructor should take an object as a reference to a constant, so it should be:
A(const A &a){ cout << "Copy Constructor of A is acting" << endl; }
Think copy constructors accept const ref
try
A(const A &a) { cout << "Copy Constructor of A is acting" << endl ; }
Hope that helps
Source: https://habr.com/ru/post/1311224/More articles:Cachemanager Application for ASP.NET - cachingBest timeout detection for synchronous operations - c #How to use Selenium, how can I check a web interface that returns XML instead of HTML? - htmlPossible way to connect database to exe - c #Java method for formatting String fields - javaDrupal: many fields / content types are equal to * many * tables, and after the dot makes MySQL very slow - mysqlOracle (PL / SQL): UPDATE RETURNING at the same time? - oracleWhat are the โcoolโ use cases for SharePoint? - sharepointDoes Groovy 1.7 change the "final"? - groovyWordPress Personalized Message Type - wordpressAll Articles