Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string.h>
- class CPU
- {
- private:
- char* name;
- int cores;
- public:
- CPU(char* name, int cores)
- {
- if (name == nullptr)
- {
- this->name = nullptr;
- }
- else
- {
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- }
- this->cores = cores;
- }
- CPU(const CPU& cpu)
- {
- this->cores = cpu.cores;
- if (this->name != nullptr)
- {
- delete[] this->name;
- }
- if (cpu.name == nullptr)
- {
- this->name = nullptr;
- return;
- }
- this->name = new char[strlen(cpu.name) + 1];
- strcpy(this->name, cpu.name);
- }
- ~CPU()
- {
- if (name != nullptr)
- {
- delete[] name;
- }
- }
- void setName(char* name)
- {
- if (this->name != nullptr)
- {
- delete[] this->name;
- }
- if (name == nullptr)
- {
- this->name = nullptr;
- return;
- }
- this->name = new char[strlen(name) + 1];
- strcpy(this->name, name);
- }
- char* getName()
- {
- char* toReturn = new char[strlen(this->name) + 1];
- strcpy(toReturn, this->name);
- return toReturn;
- }
- void setCores(int cores)
- {
- this->cores = cores;
- }
- int getCores()
- {
- return cores;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment