pointers to array (dynamic arrays)

Are you allowed to have pointers to some int and have that same pointer array act as a normal array later on in the program?

Here is what I'm supposed to do:
Implement addFish, which (dynamically) adds a new Goldfish into the Aquarium, with the specified memory capacity. If the fish cannot be added because the Aquarium already has MAX_Fish many fish residing, return false and don't add any. Otherwise, return true.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
const int MAX_FISH = 20;
class Aquarium
{
  public:
     Aquarium();
     bool addFish(int capacity);
     Goldfish *getFish(int n);
     void oracle();
     ~Aquarium();
  private:
     Goldfish *m_fish[MAX_FISH]; // <------- here is a pointer 
     int m_nFish; 
};
bool Aquarium::addFish(int capacity)
{
  if (m_nFish >= 20)
     return false;
  else 
     m_fish[m_nFish] = new Goldish(capacity); // how can we say m_fish here if it was a pointer (where i put the other comment)
     m_nFish++;
     return true; 
}
  
Last edited on
Topic archived. No new replies allowed.