c++ - Declare class object with parameters without using if...else -
i new in c++ , seek write cache simulator. constructor of class cache
cache (int, int, int, int, cache *); //declare
and in main()
, trying create objects according variable:
int main() { if ( l2_size == 0 ) //only 1 level of cache { cache l1(l1_size, blocksize, l1_assoc, inclusion, 0); } else //2 level of caches { cache l2(l2_size, blocksize, l2_assoc, inclusion, 0); cache l1(l1_size, blocksize, l1_assoc, inclusion, &l2); } }
the issue not able access l1 , l2 since scope within if...else.
besides, i've tried using ? : operator implement this, still error:
no match ternary operator.
is there way this? thanks!
something this, perhaps:
cache *l2 = 0; cache *l1 = 0; if (l2_size) { l2 = new cache(l2_size, blocksize, l2_assoc, inclusion, 0); } l1 = new cache(l1_size, blocksize, l1_assoc, inclusion, l2);
i'm sure there other possibilities.
c++
No comments:
Post a Comment