no name space
This commit is contained in:
@@ -170,20 +170,19 @@ ClassName& operator=(const ClassName& other);
|
|||||||
```cpp
|
```cpp
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
using namespace std;
|
|
||||||
|
|
||||||
class MyClass {
|
class MyClass {
|
||||||
private:
|
private:
|
||||||
string name; // Using a standard string (no pointers)
|
std::string name;
|
||||||
public:
|
public:
|
||||||
MyClass(const string& initName) : name(initName) {}
|
MyClass(const std::string& initName) : name(initName) {}
|
||||||
|
|
||||||
MyClass& operator=(const MyClass& other) {
|
MyClass& operator=(const MyClass& other) {
|
||||||
name = other.name; // Copy data
|
name = other.name; // Copy data
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
void print() const { cout << "Name: " << name << endl; }
|
void print() const { std::cout << "Name: " << name << std::endl; }
|
||||||
};
|
};
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user