Мне нужно посчитать, сколько раз моя публичная функция-член создает новые данные в цикле.
Каждый раз, когда данные читаются, они сохраняются в приватном доступном члене. Ничего не перезаписано.
// my classType.h
const int ImpliedIndex = 1000;
class classType
{
private:
char privateMember[ImpliedIndex];
char privateMember2[ImpliedIndex];
public:
static void myMemberCounter;
void printMyInformation():
void mySupplier(const char[] );
...
};
//classType.cpp
int globalCounter = 0;
void classType::printMyInformation()
{
...
cout << privateMember << endl;
cout << globalCounter++ << endl;
}
void classType::mySupplier( const char buff[] )
{
strcpy( privateMember, buff );
}
// The main should clear things up a bit.
// main.cpp
int main()
{
while ( !inFile.eof() )
{
for ( int x = 0; x < 20; x++ )
{
// do file I/O here
// save each line of file into an temp array
// supply temp array with a routine defined in myClass
// re-use temp array until we run out of file
}
}
//close file
Мне нужно изменить 20 на переменную. Обратите внимание, что в classType я использовал globalCounter для получения количества типов.
То, что я хотел сделать, это globalCounter = memberCounter;
Но я должен повторно объявить обе эти переменные, и я не могу использовать myClass[ImpliedIndex].memberCounter
с оператором присваивания (=) или оператором двоичного ввода (<<). </p>