Hello! Thank you for taking the time to help me out. I am having a problem with a program that I wrote, which is supposed to keep information about a CPU and a Computer, such as brand name, memory, and other details. The problem I am having is with the setCPU function inside the Computer.cpp file, almost at the bottom of the code I am posting. This function is supposed to set the details about the CPU, but the problem I am having is with accessing the variables of the CPU.h file inside the Computer.cpp file. I have done "#include CPU.h" but it doesn't work. Can someone help me figure out how to access the variables type and speed in Computer.cpp?
Thank you in advance for any help you can provide! Here are three of my files, CPU.h, Computer.h, and Computer.cpp (I think they are the relevant ones):
Code:// CPU.h // protections #ifndef CPU_H #define CPU_H using namespace std; class CPU { // private variables private: string type; int speed; // public functions public: CPU(); ~CPU(); string getType(); int getSpeed(); void setType(string type); void setSpeed(int speed); void printInfo(); }; #endifCode:// Computer.h // protectors #ifndef Computer_H #define Computer_H using namespace std; // CPU class so that everything compiles correctly class CPU; class Computer { // private variables private: string brandName; CPU *cpu; int memory; double price; // public functions public: Computer(); ~Computer(); string getBrandName(); CPU * getCPU(); int getMemory(); double getPrice(); void setBrandName(string newBrandName); void setCPU (string cpuType, int cpuSpeed); void setMemory (int memoryAmount); void setPrice (double newPrice); void printInfo(); }; #endifCode:// Computer.cpp #include <iostream> #include <string> #include <cstdlib> #include "Computer.h" #include "CPU.h" using namespace std; // constructor Computer::Computer() { brandName = "?"; CPU *cpu = new CPU(); memory = 0; price = 0.0; } // destructor Computer::~Computer() { delete cpu; cout << "The computer " << brandName << " is being destroyed." << endl; } // mutator functions set the variables to the new values void Computer::setCPU (string cpuType, int cpuSpeed) { *cpu->type = cpuType; *cpu->speed = cpuSpeed; }



LinkBack URL
About LinkBacks




I used to be an adventurer like you... then I took an arrow to the knee.