I'm trying to create an array (c++) that consists of 4 objects and I'm using this syntax, something is obviously wrong, but what?
for (int octet = 0; octet < 4; octet++) {
cout << "OCTET NO." << octet << endl;
cout << "IP: "; cin >> ip;
cout << "Subnet: "; cin >> subnet;
networkOctet[octet] = networkOctet(ip, subnet); //The line where the problem is
}
Thank you for your help!
!-- UPDATE --!
Allright, so I changed the code to this but now it says "no matching constructor for initialization of 'networkOctet[4]'"... I have a constructor that is declared, defined and works perfectly on objects that are not in arrays.
Updated code:
int ip;
int subnet;
networkOctet networkOctetObject[4];
for (int octet = 0; octet < 4; octet++) {
cout << "OCTET NO." << octet << endl;
cout << "IP: "; cin >> ip;
cout << "Subnet: "; cin >> subnet;
if (octet == 3) {
networkOctetObject[octet] = networkOctet(ip, subnet, true);
}
else {
networkOctetObject[octet] = networkOctet(ip, subnet, false);
}
}
networkOctetto something likegetNetworkOctetnetworkOctetis the class name. You can't use class name as an array variable