Error handling when using Boost NonCopyable

I have been using a Boost NonCopyable library in Microsoft Visual Studio 2013.

What I have is the following error message:



Error 1 error C2280: 'boost::noncopyable_::noncopyable::noncopyable(const boost::noncopyable_::noncopyable &)' : attempting to reference a deleted function c:\users\john\documents\visual studio 2013\projects\donttread\donttread\donttread.cpp 18 1 DontTread

Now what I want to rectify the error is to throw an exception, so that the program can compile smoothly.

Any questions or comments?

JohnDBCT



closed account (10X9216C)
Just don't use noncopyable. The reason to use that class is for that error. If you want to suppress that error than you don't want to use the noncopyable class (you want your class to be copyable).
I want to clarify this better, so that it would be possible to rectify any compile errors when I am accessing the noncopyable library.

Here is the following source code:

#include <boost/noncopyable.hpp>
#include <iostream>

class A : public boost::noncopyable {
public:
A() { std::cout << "In A \n" << std::endl; }

class AnError
{};
void Func()
{
if () //error condition
throw AnError();
}
};
int main()
{
try
{
A object1;
A object2(object1);
object1 = object2;
}
catch (A::AnError)
{
//tell user about error.
}
return 0;
}

Any questions or comments on how I can improve this preceding source code?

JohnDBCT
Any questions or comments on how I can improve this preceding source code?

Yes. Fix the error flagged by the compiler. Then there is no reason to inform user that an error that should never occur has, in fact, occurred.
closed account (10X9216C)
//tell user about error.

In this case you are the user (of noncopyable) and boost is telling you the error. This isn't C#, python or whatever you are trying to imitate.
Topic archived. No new replies allowed.