Line 19 is incorrect. The correct syntax for new is ball* b = new ball[i]; . But this is likely not what you want. If it is, then remember to call delete[] b; when b is no longer needed. e.g:
#include<iostream>
#include<string>
usingnamespace std;
class ball{
public:
int rad=10;
};
int main(){
string s;
cout << "Add ball?";
cin >> s;
int i=1;
if (s == "y"){
ball* b = new ball[i];
i++;
cout << b[i].rad+i;
delete[] b;
}
}
However there is an error on line 21 where you are accessing beyond the array of objects.
I will leave you with what I think you wanted, but still with the error on line 21.
The reason you use a pointer for ball (b) is new returns a pointer. But in Ball b[1]b is also a pointer, although to static memory. b holds the pointer to the memory, while b[number] dereferences the memory. you could also do *(b+number) to do the same thing. You can read more here http://www.cplusplus.com/doc/tutorial/pointers/