I can't build below code(vs2013) blocks and getting error "error C2248: 'Concurrency::critical_section::critical_section' : cannot access private member declared in class 'Concurrency::critical_section'"
Anyone can help explain why this is happening? Thanks
#include <ppl.h>
class Class1{
public:
concurrency::critical_section _cs;
int f1;
Class1(int f){ f1 = f; }
};
class Class2{
public:
std::vector<Class1> v1;
Class2(){ v1.push_back(Class1(1)); v1.push_back(Class1(2)); }
};
int _tmain(int argc, _TCHAR* argv[])
{
Class2 c2();
return 0;
}
concurrency::critical_sectionis neither copyable nor movable (this was done in the old-fashioned way of making its copy constructorprivate, hence the error you get). Therefore,Class1as written cannot be copied or moved either, and you can'tpush_backit into a vector.To fix this, you can write your own copy constructor and copy assignment operator that copies only
f1:Side note:
Class2 c2();declares a function returning aClass2, not a value-initialized object.Side note 2: The error messages in VS's "Error List" are generally incomplete. You'll want to check the Build Output for the full error log. In this case, the full error log on my VS2013 is: