This is the final topic I'm making. This isn't the full program, I only included relevant parts. It's probably very simple for you guys.
I have 3 classes, 1 creates objects that hold a name (string), "DatabaseNames", 1 creates objects that hold an address (string), "DatabaseAddress", and the last 1 is "DatabaseGeneral" which creates 100 objects from each class. I want to implement a function below...
DatabaseAddress getAddress(DatabaseNames id); inside the DatabaseGeneral class. (see below)
(DatabaseNames.h)
Code
#ifndef DATABASENAMES_H
#define DATABASENAMES_H
#include <string>
class DatabaseNames {
public:
std::string name;
};
(DatabaseAddress.h)
Code
#ifndef DATABASEADDRESS_H
#define DATABASEADDRESSL_H
#include <string>
class DatabaseAddress {
public:
std::string address;
};
(DatabaseGeneral.h)
Code
#ifndef DATABASEGENERAL_H
#define DATABASEGENERAL_H
#include "DatabaseNames.h"
#include "DatabaseAddress.h"
#include <string>
class DnaDatabase {
public:
DatabaseNames recordN[100]; //holds 100 names, recordN[x] corresponds to recordA[x]
DatabaseAddress recordA[100]; //holds 100 addresses, of the 100 names
void addRecord(DatabaseNames name, DatabaseAddress address); //used to fill up the 200 objects
DatabaseAddress getAddress(DatabaseNames id); //the member function thats giving me problems
};
I want to implement DatabaseAddress like so:
Code
DatabaseAddress getAddress(DatabaseNames id){
for (int i = 0; i < 100; i++){
if (id.name == recordN[i].name){
return recordA[i].address;
}
}
}
I know this doesn't work, I get a "recordN and recordA was not declared in this scope". But what's the easiest way to implement this without changing the member function's interface? i.e: DatabaseAddress getAddress(DatabaseNamesid);