Class Arrays Problem

Hi everyone,

I have another problem that I can seem to get around in C++. I have a class that is a multi dimensional array. I m trying to initialize the array using an init function and having problem passing it to the function. My code is posted below:


// classes example
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <iomanip>
using std::ifstream;

using namespace std;

class Cache {
int LRU_counter;
public:
void set_counter (int);
int _LRU_counter () {return (LRU_counter);}
};

void Cache::set_counter (int x) {
LRU_counter = x;
}

void L1_LRU_Counter_Init (Cache);

double L1_Number_Of_Set;
int L1_Assoc = 8;

int main (int argc, char *argv[]) {

L1_Number_Of_Set = 32.0; //This is computed in the real file


Cache L1[int(L1_Number_Of_Set)][L1_Assoc];

L1_LRU_Counter_Init (L1);

for(int y = 0; y < int(L1_Number_Of_Set); y++) {
for (int z = 0; z < L1_Assoc; z++) {
cout << L1[y][z]._LRU_counter() << " ";
}
cout << endl;
}

return 0;

}

void L1_LRU_Counter_Init (Cache data[][]){

for(int y = 0; y < int(L1_Number_Of_Set); y++) {
for (int z = 0; z < L1_Assoc; z++){
data[y][z].set_counter (1);
}
}

}

thnx for the help in advance :)
Several things. For your last defined function, you need to specify the depth of the array in its second dimension (like [][size]). Soz.

Second, you mis-declared your L1_LRU_Counter_Init to take as an argument a single Cache. No no, you want to declare it to take a Cache data[][size]. Else chaos ensues.

Enjoy. ;)

-Albatross
Last edited on
And use code blocks so people can read your code easier** (:
What Albatross said. Beat me to the post.
Topic archived. No new replies allowed.