#include <iostream>
#include <vector>
#include <iomanip>
using namespace std;
class DAI //DynamicArrayInput
{
public :
void getCountry()
{
cout << "Country : ";
cin >> Country;
}
void putCountry()
{
cout << Country << endl;
}
static int putCount()
{
return count;
}
private :
static int count;
char Country[30];
};
int main()
{
vector< DAI > A;
DAI * B; //HOW IS THE POINTER B POINTING TO VECTOR A EVEN THOUGH I //HAVE NOT INITIALIZED IT LIKE B = A
//OR DAI * B;
int answer;
cout << "How many countries do you want to enter : ";
cin >> answer;
for(int i=0; i < answer; i++)
{
A.push_back(DAI());
B[i].getCountry();
}
cout << "Printing name of countries\n";
for(int i=0; i < 3; i++)
{
B[i].putCountry();
}
cout << "size of vector A is " << A.size();
return 0;
}
My aim is to use arrays of objects i like dynamically so that i can input any number of countries I don't want to use something like B[3] with something known array size but i am unable to do.
It worked on g++ compiler but it did not work on devC++ as the pointer
DAI * B;
is not initialised then how do I try to build my program I can't do
DAI * B = A;
also because DAI is a class type and A is a vector( vector<DAI> A)
please help??