Plot* buildAndCacheP(int x, int y) { int linear_index = y * width + x; Plot* cachedPtr(cache[linear_index]); if (cachedPtr != nullptr) { //std::cout << "from cache: " << cachedPtr << std::endl; return cachedPtr; } Plot *p = Plot::create(x, y, width); cache[p->Id()] = p; //std::cout << "buildAndCache: " << cache[p->Id()] << " => " << x << ", " << y << std::endl; return p; }