#include <iostream>
usingnamespace std;
class a
{
public: int k;
void ar(a b[66]); // <--- problematic line
}ob;
void a::ar(a b[10])
{
cout << "Hello World d" << endl << b[0].k << ' ' <<b[1].k ;
}
int main()
{
a b[10];b[0].k=2;b[1].k=3;
ob.ar(b);
return 0;
}
shows the undefined structure error but if I replace the prototype of the member function with void ar(a* b); or even if I have a single parameter instead of an array, error disappears. But isn't the class definition incomplete in all 3 cases? note : I am using TC++.
that also shows the error. My question is if the compiler has a problem with the 'a' class definition not being complete by line 8 where it is used, then how is it okay with the other two cases mentioned in the first post?
When it comes to function parameters, a b[] and a* b (are supposed to) mean the same thing. And a b[1], a b[10], a b[66], a b[1024], etc as well; the number in the []s is ignored. (Well, you're declaring with 66 and defining with 10)
struct B ; // incomplete type
struct A
{
typedefint incomplete[] ; // incomplete array of complete type
typedef B also_incomplete[] ; // incomplete array of incomplete type
int k;
// A is an incomplete type at this point
bool foo( A a[66], incomplete b, also_incomplete c )
{
// A is a complete type by the time the compiler gets to this
// definitions of members are parsed later,
// after the declarations of all members have beenn seen.
A aa = a[5].bar(*this) ;
constvoid* pv = b ;
return pv != &aa && pv != c ;
}
A bar( A a /* A is an incomplete type here */ )
{ return a ; /* A is a complete type here */ }
const B& bar( B& b ) { return b ; }
static A s1[] ;
static incomplete s2 ;
static also_incomplete s3 ;
};
A A::s1[5] ; // A::s1 is complete now
int A::s2[25] ; // A::s2 is complete now
struct B { /* ... */ } ;
// B is a complete type here
B A::s3[32] ; // A::s3 is complete now