Hi all, the code below gives compilation error when I try to create test t[2]; because there is no default constructor for this.
But if I create Test t[2] = {test(1,2), test(2,3)};
Then it works fine.
1)But think of a situation, if we want to create more then 100 array element. We need to create 100 element in the curly braces like.. Test t[100] = {test(1,2), test(1,2)……/100 times/};
The above code is difficult to maintain. One more solution is to create public member function which takes 2 integers and run in a loop. This solves the problem but i want to know any other good method.
2) If I create it using new
Test *t = new test[10];
I get compilation error(No default constructor). How to solve this.
class test
{
int _a;int _b;
public:
test(int a, int b);
void display();
};
int _tmain(int argc, _TCHAR* argv[])
{
test t[10];
for (int i = 0 ; i< 10; i++)
t[i].display();
}