/*
I'm trying to develope a fried class (c2) capable of accessing
class cl for the purpose of gathering data. I want to pass a
cl pointer to c2::runShow. runShow would subsequently pass the
pointer to other c2 member functions. The code compiles without
error or warnings. It reads the first object of the array of
objects, but when c2::prn increments i, the following error
message is displayed:
Loaded 'C:\WINDOWS\SYSTEM\KERNEL32.DLL', no matching symbolic
information found. First-chance exception in testCPP.exe:
0xC0000005: Access Violation.
I know it can't locate the subsequent objects of the array of
objects and therefore has an access violation. I can't figure
out why.
If you could point out my blounder, I'd be happy.
Thanks
*/
#include <iostream>
class cl {
int a, b, c;
static int cntr;
public:
cl( int j, int k, int l )
{ a = j; b = k; c = l; cntr++;
std::cout << "Object " << cntr << '\n'; }
~cl() { std::cout << "Object " << cntr-- << " destroyed.\n"; }
int get_a () { return a; }
int get_b () { return b; }
int get_c () { return c; }
friend class c2;
};
class c2 {
public:
void prn( cl **obj )
{
std::cout << "Using class cl access function\n\n";
for( int i = 0; i < 3; i++ ) {
std::cout << obj[i]->get_a() << ", ";
std::cout << obj[i]->get_b() << ", ";
std::cout << obj[i]->get_c() << ",\t";
} // end for
std::cout << "\n\n";
} // end prn
void runShow( cl *ob )
{
prn( &ob );
} // end show
}; // end c2
int cl::cntr = 0; // initialize counter
int main() {
cl ob[3] = { cl(1, 4, 7), // create array of objects
cl(2, 5, 8),
cl(3, 6, 9) }; // initializer
c2 m; // create friend object
m.runShow( ob );
return 0;
} // end



LinkBack URL
About LinkBacks


