Skip to content

Commit 4b444d2

Browse files
committed
Update cpp-for-cscharp.md
1 parent 4408816 commit 4b444d2

1 file changed

Lines changed: 37 additions & 6 deletions

File tree

content/posts/cpp-for-cscharp.md

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -355,25 +355,56 @@ by copying a different value to itself, often using an overloaded copy operator.
355355
| **Copy Assignment** | ``x = value;`` | copy operator (not initialization) |
356356
| **Move Assignment** | ``x = std::move(value);`` | move operator (not initialization) |
357357

358+
The constructors and operators used here can be fully custom implemented for your
359+
custom type by simply implementing these function signatures in your type:
360+
```cpp
361+
T(); // constructor
362+
T(T&); // copy constructor
363+
T(T&&); // move constructor
364+
T& operator=(T&); // copy assignment operator
365+
T& operator=(T&&); // move assignment operator
366+
```
358367
359-
The actual constructor or operator can be custom:
368+
Here is a simple example of how those signatures might be implemented:
360369
```cpp
361370
class Foo
362371
{
372+
373+
public:
374+
363375
// constructor
364-
Foo();
376+
Foo()
377+
{
378+
// implement logic
379+
}
365380
366381
// copy constructor
367-
Foo(const Foo& other);
382+
Foo(const Foo& other)
383+
{
384+
// implement logic
385+
}
368386
369387
// move constructor
370-
Foo(Foo&& other);
388+
Foo(Foo&& other)
389+
{
390+
// implement logic
391+
}
371392
372393
// copy assignment operator
373-
Foo& operator=(const Foo& other);
394+
Foo& operator=(const Foo& other)
395+
{
396+
// implement logic
397+
398+
return *this;
399+
}
374400
375401
// move assignment operator
376-
Foo& operator=(Foo&& other);
402+
Foo& operator=(Foo&& other)
403+
{
404+
// implement logic
405+
406+
return *this;
407+
}
377408
}
378409
```
379410

0 commit comments

Comments
 (0)