undefined structure ( TC++ )

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 #include <iostream>

using namespace 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++.
Change the line to void ar(a b[]);

HTH,
Aceix.
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?
even though it's horrible code i get no warnings or errors. weird.

(vs 2010, win8)
error is only in TC++
Have you tried using void ar(a* b); instead?

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)

Andy
Last edited on
> error is only in TC++

Yes; do not use any version of any compiler that pre-dates the 1998 standard.

This is perfectly fine; there are many constructs in C++ where a type can be used even if it is incomplete.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
struct B ; // incomplete type

struct A
{
    typedef int 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) ;
        const void* 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 
Topic archived. No new replies allowed.