Questions tagged [noncopyable]

The boost::noncopyable class is used as a base class to make a C++ type unable to be copied or assigned. This tag is for the boost library utility noncopyable.

The boost::noncopyable class is used as a base class (usually private) to make a C++ type unable to be copied or assigned.

It is intended to be used as a private base. boost::noncopyable has private (under C++03) or deleted (under C++11) copy constructor and a copy assignment operator and can't be copied or assigned; a class that derives from it inherits these properties.

Use this tag is for the boost library utility noncopyable.

76 questions
10
votes
1 answer

How to store persistent handles in V8?

I want my class to hold a v8::Context and a v8::External as members. Therefore, I thought I had to use persistent handles. class ScriptHelper { public: ScriptHelper(v8::Persistent Context) : context(Context) { // ... } …
danijar
  • 32,406
  • 45
  • 166
  • 297
10
votes
2 answers

Prohibiting definition of a copy constructor in an inherited class

I want to make an abstract base class non-copyable and force any classes that derive from it to be non-copyable. The below code uses Boost's noncopyable as defined in noncopyable.hpp yet still allows D, the derived class, to define a copy…
steve9164
  • 426
  • 2
  • 11
  • 22
9
votes
4 answers

C++ const lvalue references

Assuming I have: class A which is non-copyable class B which has as a member, const A& a (and takes an A in its constructer and sets it in its initialization list) a function A GenerateA(); Does this mean that it should be valid to…
please delete me
  • 711
  • 2
  • 9
  • 17
9
votes
3 answers

C++11 array initialization with a non-copyable type with explicit constructor

I have a (third-party) class which is non-copyable. I'd like to initialize an array of them. Here's my best attempt: #include class Thing { public: explicit Thing(int) {} Thing(const Thing&) = delete; }; int main() { …
John Zwinck
  • 239,568
  • 38
  • 324
  • 436
8
votes
5 answers

Virtual destructor for boost:noncopyable classes?

I have a question about the following code: class MyClass : private boost::noncopyable { public: MyClass() {} virtual ~MyClass() {} } class OtherClass : private boost::noncopyable { private: MyClass* m_pMyClass; } My thoughts…
TERACytE
  • 7,553
  • 13
  • 75
  • 111
7
votes
4 answers

Is copying automatically prohibited in classes derived from classed derived from Boost noncopyable?

For example: class Foo : boost::noncopyable { // ... }; class Bar : public Foo { // ... }; Is Bar non-copyable?
Emile Cormier
  • 28,391
  • 15
  • 94
  • 122
7
votes
4 answers

C++ Non copyable except sometimes

I find that making a class non-copyable helps me a lot with my code quality. Initially I did this with boost::noncopyable, but I found the VC++ compiler errors to be not as helpful as with private members (double clicking lead to the wrong place in…
Cookie
  • 12,004
  • 13
  • 54
  • 83
7
votes
4 answers

C++ container with non-copyable non-movable element type

I need a container of elements that are neither copyable nor movable. These elements are not default constructible, but their constructors get identical arguments. The size of the container does not change during it's lifetime. It should be as…
Ralph Tandetzky
  • 22,780
  • 11
  • 73
  • 120
6
votes
2 answers

Putting non-copyable objects into std-containers

Is this class design the standard C++0x way to prevent copy and assign, to protect client code against accidental double-deletion of data? struct DataHolder { int *data; // dangerous resource DataHolder(const char* fn); // load from file or…
towi
  • 21,587
  • 28
  • 106
  • 187
6
votes
3 answers

How to create a container of noncopyable elements

Is there a way use STL containters with non-copyable elements? something like this: class noncopyable { noncopyable(noncopyable&); const noncopyable& operator=(noncopyable&); public: noncopyable(){}; }; int main() { …
Vargas
  • 2,125
  • 2
  • 33
  • 53
5
votes
1 answer

Boost non-copyable weirdness

I have a class inheriting from boost::noncopyable; say, with header excerpt as follows: class A : boost::noncopyable { ... blah ... private: struct impl; boost::scoped_ptr m_impl; }; Then in one of the projects of my solution,…
squashed.bugaboo
  • 1,338
  • 2
  • 20
  • 36
5
votes
1 answer

Does OpenMP copy private objects?

I'm writing a program that reads huge file (3x280 GB) and does a fitting procedure to the data in the file. It's pretty convenient to parallelise such a program, where this is easily done with OpenMP. The thing I don't understand is how private…
The Quantum Physicist
  • 24,987
  • 19
  • 103
  • 189
4
votes
4 answers

Making a class non-copyable: Private undefined methods vs Deleted methods

Prior to C++11, I saw code like this: class Car { public: Car() {} private: Car(const Car&); Car& operator=(const Car&); }; For C++11 (and later), I see code like this: class Car { public: Car() {} private: Car(const Car&) = delete; …
kevinarpe
  • 20,319
  • 26
  • 127
  • 154
4
votes
2 answers

C++ - how to reinitialize object repeatedly?

I'm trying to implement this logic in C++: Object obj(args); while (obj.isOK()) { obj = obj.next(); } But I can't use this exact code because Object inherits boost::noncopyable so it has no assignment operator. I can add methods and…
Drew
  • 12,578
  • 11
  • 58
  • 98
4
votes
3 answers

How to exclude portions of text when copying

Im trying to make some text non-copyable, my aim isn't to stop people from copying text from my website but more to make it easier to use. I have a list of files with file size's but I want to only copy the file names and not the file size. So far…
Mint
  • 14,388
  • 30
  • 76
  • 108