Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/andreicherniaev/unique_ptr_operator_overloading_unique_ptr
unique_ptr operator overloading with unique_ptr or QScopedPointer test
https://github.com/andreicherniaev/unique_ptr_operator_overloading_unique_ptr
Last synced: about 2 months ago
JSON representation
unique_ptr operator overloading with unique_ptr or QScopedPointer test
- Host: GitHub
- URL: https://github.com/andreicherniaev/unique_ptr_operator_overloading_unique_ptr
- Owner: AndreiCherniaev
- License: apache-2.0
- Created: 2024-09-12T16:27:49.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2024-09-13T03:35:53.000Z (4 months ago)
- Last Synced: 2024-09-14T07:01:44.381Z (4 months ago)
- Language: C++
- Homepage: https://forum.qt.io/topic/158679/unique_ptr-operator-overloading-is-disabled-by-qscopedpointer
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
There are three ways to declare object: use (just) object, use object in QScopedPointer or object in std::unique_ptr.
```
class1 cl1;
std::unique_ptr cl2(new class1());
QScopedPointer cl3(new class1());
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
QDataStream myStream(&buffer);
myStream << cl1 << " " << *cl2.get() << " " << *cl3.get();
qDebug() << buffer.data();
```
output
```
"\x00\x00\x00\x0E\x00""d\x00""e\x00""f\x00""a\x00u\x00l\x00t\x00\x00\x00\x05 \x00\x00\x00\x00\x0E\x00""d\x00""e\x00""f\x00""a\x00u\x00l\x00t\x00\x00\x00\x05 \x00\x00\x00\x00\x0E\x00""d\x00""e\x00""f\x00""a\x00u\x00l\x00t"
```
## Features
class1 contains private field but operator overloading containd `friend` keyword to accsess to private field.
## How to build
```
git clone https://github.com/AndreiCherniaev/unique_ptr_operator_overloading_unique_ptr
cd unique_ptr_operator_overloading_unique_ptr
mkdir build/
cmake -S src/ -B build/
cmake --build build/ --parallel
```
## See also
Friend project How to overload the QDataStream &operator << and >> [here](https://github.com/AndreiCherniaev/overload_QDataStream_example)