Your code should work.
And, at least, it works in the fake scenario I created to make it run
#include <iostream>
#include <vector>
using namespace std;
class Housing
{
float rent;
string name;
public:
Housing(string name, float rent):rent(rent), name(name){}
int getRent(){return rent;}
string toString(){return name;}
};
class HousingRegister
{
int nrOfHouses;
vector<Housing * > housing;
public:
HousingRegister(int houses):nrOfHouses(houses)
{
for ( int n=0; n<houses; ++n)
{
string name = "foo";
name.append( 1, (char)('0' + n));
float rent = 1000.0f * (n+1);
housing.push_back( new Housing( name, rent ));
}
}
~ HousingRegister()
{
for (size_t n=0; n<housing.size(); ++n)
delete housing[n];
}
void printBythePrice(string *arr, float max) const;
int getnrOfHouses() const { return nrOfHouses; };
};
void printBythePrice(const HousingRegister &house){
float max;
string *arr = new string[house.getnrOfHouses()];
cout << "Enter the price";
cin >> max;
house.printBythePrice(arr, max);
for (int i = 0; i < house.getnrOfHouses(); i++)
{
cout << arr[i];
}
delete[] arr;
}
void HousingRegister::printBythePrice(string *arr, float max)const {
int index = 0;
for (int i = 0; i <nrOfHouses; i++)
{
if (housing[i]->getRent() >= max)
{
arr[index] = housing[i]->toString();
index++;
}
}
}
int main()
{
HousingRegister hr(5);
printBythePrice(hr);
}