I'm getting an error when I attempt compiling my program. I left out the block.cc/h files because they don't pertain to the problem at hand at the moment. I'm building a cache simulator but the problem I'm currently facing does not have much to do with the cache end of things, but more so C++ syntax mainly vectors. When I compile I get the following error :
-bash-4.1$ g++ simulation.cc
In file included from simulation.cc:1:
cache.cc: In constructor âCache::Cache(int, int, int, int, int)â:
cache.cc:23: error: â((Cache*)this)->Cache::vâ does not have class type
cache.cc: In member function âint Cache::read(long unsigned int)â:
cache.cc:39: error: â((Cache*)this)->Cache::vâ does not have class type
Any pointers would be greatly appreciated, thank you very much!
Here are the files containing my code:
simulation.cc
Code:
#include "cache.cc"
int main(){
int M = 32;
int C = 1024;
int B = 2;
int E = 1;
int S = 4;
int m = 4;
// there are 4 block offset bits (b)
// calculated in other classes as needed?
//int S =
//int t =
//int s = //# of set index bits
//int b = //# of block offset bits
Cache* cache = new Cache(M,C,B,E,S);
cache->read(0);
cache->read(1);
cache->read(2);
cache->read(3);
cache->read(0);
cache->read(1);
cache->read(2);
}
cache.cc
Code:
Cache::Cache() {
//instance variables
M = 0;
C = 0;
B = 0;
E = 0;
S = 4;
vector<set*> v(S); // holds list of sets
}// Constructor
Cache::Cache(int mainMemSize, int cacheSize, int blockSize, int numOfLinesPerSet,
int numOfSets) {
int M = mainMemSize; //size of main memory address space (m in the book)
int C = cacheSize; //size of cache in bytes(C in book)
int B = blockSize; //size of blocks(B in the book)
int E = numOfLinesPerSet; //set associativity (E in the book) - is the number of cache lines/blocks per set
int S = numOfSets;
vector<set*> v(S);
for(int i = 0; i < numOfSets; i++){
this->v.at(i) = new set();
}
}
int Cache::read(unsigned long memAddress){
// split address into 3 sections - tag, set index, and block index
// works for 32 bit?
int offset = (memAddress >> 0) & ((1 << 6) -1);
int setIndex = (memAddress >> 6) & ((1 << 5) -1);
int tag = (memAddress >> 11) & ((1 << 21) -1);
int validBit = 0; // 1 or 0 based on if block is used or not
//use set index to call right set
int hitFlag = v.at(0)->set.read(offset, tag);
if (hitFlag = 0) {
return hitFlag; // if cache hit
} else if (hitFlag = 1) {
// return 1 if cache miss
} else {
// return 2 if cache miss with a write back on eviction
}
}
int Cache::write(unsigned long memAddress){
return 0; // if cache hit
// return 1 if cache miss
// return 2 if cache miss with a write back on eviction
}
int dumpCache(){
//return # of cache values needed to be written back to main memory
}
void Cache::display() {
//cout for debug purposes
cout << "Main Memory Size is : " << this->M << "\n";
cout << "Cache size is : " << this->C << "\n";
cout << "Block size is : " << this->B << "\n";
cout << "Number of lines per set is : " << this->E << "\n";
//cout << "Main Memory Size is : " << this.S << "\n";
}
cache.h
Code:
#include "set.cc"
class Cache {
private:
int M;
int C;
int B;
int E;
int S;
vector<set*> v(); // holds list of sets
public:
Cache();
Cache(int mainMemSize, int cacheSize, int blockSize, int numOfLinesPerSet, int numOfSets);
int read(unsigned long memAddress);
int write(unsigned long memAddress);
void display();
};
set.cc
Code:
#include "set.h"
set::set() {
//instance variables
E = 0;
vector<block*> v(E); // holds list of lines/blocks
validBit = 0;
}
// Constructor
set::set(int E, int validBit) {
this->E = E;
this->validBit = validBit;
}
int set::read(int offset, int tag){
//ve.push_back();
return 0; // if cache hit
// return 1 if cache miss
// return 2 if cache miss with a write back on eviction
}
int set::write(int offset, int tag){
return 0; // if cache hit
// return 1 if cache miss
// return 2 if cache miss with a write back on eviction
}
/*void set::display() {
//cout for debug purposes
}*/
set.h
Code:
#include "block.cc"
class set {
private:
int validBit;
int E;
vector<block*> v(); // holds list of lines/blocks
public:
set();
set(int E, int validBit);
int read(int offset, int tag);
int write(int offset, int tag);
};