# new

***

**1. Creating a New Object**

```cpp
// Create a new object using the default constructor
Person* p = new Person();
```

**2. Creating an Array of Objects**

```cpp
// Create an array of 100 integers using the default constructor
int* arr = new int[100];
```

**3. Creating a Dynamically Sized Array**

```cpp
// Create a dynamically sized array using the `std::vector` class
std::vector<int> v(100);
```

**4. Creating a New Instance of a Class**

```cpp
class MyClass {
public:
    MyClass() {}
    ~MyClass() {}
};

// Create a new instance of the `MyClass` class
MyClass* obj = new MyClass();
```

\**5. Creating a New Class*

```cpp
class MyClass {
public:
    MyClass() {}
    ~MyClass() {}
};

int main() {
    // Create a new class object
    MyClass myClass;
    // ...
}
```

**6. Creating a New STL Container**

```cpp
// Create a new `std::vector` container
std::vector<int> v;
```

**7. Creating a New Thread**

```cpp
// Create a new thread
std::thread t([]() {});
```

**8. Creating a New File**

```cpp
// Create a new file
std::ofstream file("myfile.txt");
```

**9. Creating a New Process**

```cpp
// Create a new process
std::system("ls -l");
```

**10. Creating a New Socket**

```cpp
// Create a new socket
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
```

**11. Creating a New File Descriptor**

```cpp
// Create a new file descriptor
int fd = open("myfile.txt", O_RDWR);
```

**12. Creating a New Signal**

```cpp
// Create a new signal
signal(SIGUSR1, signalHandler);
```

**13. Creating a New Timer**

```cpp
// Create a new timer
timer_t timer;
```

**14. Creating a New Exception**

```cpp
// Create a new exception
throw std::runtime_error("Error message");
```

**15. Creating a New Function Pointer**

```cpp
// Create a new function pointer
int (*myFunc)(int, int) = [](int x, int y) { return x + y; };
```

**16. Creating a New Class Member Function Pointer**

```cpp
class MyClass {
public:
    int (MyClass::*myFunc)(int, int) = &MyClass::add;
    // ...
};
```

\**17. Creating a New Member Function Pointer*

```cpp
int (MyClass::*myFunc)(int, int) = &MyClass::add;
```

**18. Creating a New Static Data Member**

```cpp
class MyClass {
public:
    static int myVar;
    // ...
};
```

**19. Creating a New Abstract Class**

```cpp
class MyClass {
public:
    virtual int add(int, int) = 0;
    // ...
};
```

**20. Creating a New Pure Virtual Function**

```cpp
class MyClass {
public:
    virtual int add(int, int) = 0;
    // ...
};
```

**21. Creating a New Interface**

```cpp
class IMyInterface {
public:
    virtual int add(int, int) = 0;
    // ...
};
```

**22. Creating a New Template Class**

```cpp
template<typename T>
class MyClass {
public:
    // ...
};
```

**23. Creating a New Template Function**

```cpp
template<typename T>
int add(T x, T y) { return x + y; }
```

**24. Creating a New Operator Overload**

```cpp
class MyClass {
public:
    friend MyClass operator+(const MyClass& lhs, const MyClass& rhs) { return MyClass(); }
    // ...
};
```

**25. Creating a New Conversion Operator**

```cpp
class MyClass {
public:
    operator int() const { return 0; }
    // ...
};
```

**26. Creating a New Iterator**

```cpp
class MyClassIterator {
public:
    // ...
};
```

\**27. Creating a New Abstract Base Class*

```cpp
class MyClass : public IMyInterface {
public:
    // ...
};
```

**28. Creating a New Derived Class**

```cpp
class MyClass : public BaseClass {
public:
    // ...
};
```

**29. Creating a New Virtual Inheritance**

```cpp
class MyClass : virtual public IMyInterface {
public:
    // ...
};
```

**30. Creating a New Multiple Inheritance**

```cpp
class MyClass : public BaseClass1, public BaseClass2 {
public:
    // ...
};
```

**31. Creating a New Diamond Inheritance**

```cpp
class MyClass : public BaseClass1, public BaseClass2 {
public:
    using BaseClass1::myFunc;
    using BaseClass2::myFunc;
    // ...
};
```

**32. Creating a New Friend Class**

```cpp
class MyClass {
public:
    friend class MyFriendClass;
    // ...
};
class MyFriendClass {
public:
    // ...
};
```

**33. Creating a New Using Declaration**

```cpp
class MyClass {
public:
    using std::vector;
    // ...
};
```

**34. Creating a New Typecast**

```cpp
int myInt = 10;
double myDouble = (double)myInt;
```

**35. Creating a New Pointer**

```cpp
int myInt = 10;
int* myPtr = &myInt;
```

**36. Creating a New Reference**

```cpp
int myInt = 10;
int& myRef = myInt;
```

**37. Creating a New Const Reference**

```cpp
int myInt = 10;
int const& myConstRef = myInt;
```

**38. Creating a New Rvalue Reference**

```cpp
int&& myRvalueRef = std::move(myInt);
```

**39. Creating a New Lambda Function**

```cpp
int myVar = 10;
auto myLambda = [myVar](int x) { return x + myVar; };
```

**40. Creating a New Closure**

```cpp
int myVar = 10;
auto myClosure = [&myVar](int x) { return x + myVar; };
```

**41. Creating a New Delegate**

```cpp
using namespace std::placeholders;
auto myDelegate = std::bind(&MyClass::myFunc, _1, _2);
```

**42. Creating a New Function Object**

```cpp
class MyFunctor {
public:
    int operator()(int x) { return x * x; }
};
auto myFunctor = MyFunctor();
```

**43. Creating a New Smart Pointer**

```cpp
std::unique_ptr<MyClass> myPtr(new MyClass());
```

**44. Creating a New Weak Pointer**

```cpp
std::weak_ptr<MyClass> myWeakPtr(myPtr);
```

**45. Creating a New Shared Pointer**

```cpp
std::shared_ptr<MyClass> mySharedPtr(new MyClass());
```

**46. Creating a New Atomic Variable**

```cpp
std::atomic<int> myAtomicVar(10);
```

**47. Creating a New Condition Variable**

```cpp
std::condition_variable myCondVar;
```

**48. Creating a New Mutex**

```cpp
std::mutex myMutex;
```

**49. Creating a New Lock Guard**

```cpp
std::lock_guard<std::mutex> lock(myMutex);
```

**50. Creating a New Unique Lock**

```cpp
std::unique_lock<std::mutex> lock(myMutex);
```
