I can not figure out why this simple struct is not an aggregate? 
Author Message
 I can not figure out why this simple struct is not an aggregate?

I can not figure out why this simple struct is not an aggregate?

#pragma unmanaged

template<typename T>
struct C {
    T i;

Quote:
};

#pragma managed

__gc class Test {
    C<int> Fn() { //error C2230
        C<int> x;
        return x;
    }

Quote:
};

error C2230: 'Test' : a member function of a managed class cannot return a non-managed class or struct 'Gc<T>' unless it is an
aggregate
        with
        [
            T=int
        ]

Compiler error C2230:

'function' : a member function of a managed class cannot return a non-managed class or struct 'user-defined type' unless it is an
aggregate

If a member function in a managed class will return an unmanaged class or struct, that class or struct cannot have any of the
following:

  a.. Virtual function
  b.. Constructor
  c.. Destructor
  d.. Copy assignment operator
  e.. Base class



Sun, 24 Jul 2005 01:44:57 GMT  
 I can not figure out why this simple struct is not an aggregate?

Quote:

> I can not figure out why this simple struct is not an aggregate?

Because it is templated?

Quote:
> #pragma unmanaged

> template<typename T>
> struct C {
>     T i;
> };

> #pragma managed

> __gc class Test {
>     C<int> Fn() { //error C2230
>         C<int> x;
>         return x;
>     }
> };

> error C2230: 'Test' : a member function of a managed class cannot return a

non-managed class or struct 'Gc<T>' unless it is an
Quote:
> aggregate
>         with
>         [
>             T=int
>         ]

> Compiler error C2230:

> 'function' : a member function of a managed class cannot return a

non-managed class or struct 'user-defined type' unless it is an
Quote:
> aggregate

> If a member function in a managed class will return an unmanaged class or

struct, that class or struct cannot have any of the

Quote:
> following:

>   a.. Virtual function
>   b.. Constructor
>   c.. Destructor
>   d.. Copy assignment operator
>   e.. Base class

While struct C<int> might look like an aggregate, the general C<some_class>
definitely is not. What if some_class has a constructor?

Bo Persson



Sun, 24 Jul 2005 05:32:10 GMT  
 I can not figure out why this simple struct is not an aggregate?

Quote:
>>While struct C<int> might look like an aggregate, the general C<some_class>
>>definitely is not. What if some_class has a constructor?

However at the time of the error the compiler knows it is an int and not some_class with a constructor.
Quote:


> > I can not figure out why this simple struct is not an aggregate?

> Because it is templated?

> > #pragma unmanaged

> > template<typename T>
> > struct C {
> >     T i;
> > };

> > #pragma managed

> > __gc class Test {
> >     C<int> Fn() { //error C2230
> >         C<int> x;
> >         return x;
> >     }
> > };

> > error C2230: 'Test' : a member function of a managed class cannot return a
> non-managed class or struct 'Gc<T>' unless it is an
> > aggregate
> >         with
> >         [
> >             T=int
> >         ]

> > Compiler error C2230:

> > 'function' : a member function of a managed class cannot return a
> non-managed class or struct 'user-defined type' unless it is an
> > aggregate

> > If a member function in a managed class will return an unmanaged class or
> struct, that class or struct cannot have any of the
> > following:

> >   a.. Virtual function
> >   b.. Constructor
> >   c.. Destructor
> >   d.. Copy assignment operator
> >   e.. Base class

> While struct C<int> might look like an aggregate, the general C<some_class>
> definitely is not. What if some_class has a constructor?

> Bo Persson




Mon, 25 Jul 2005 07:35:32 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. CFile not working properly, can't figure out why (last message not sent properly)

2. Why not return an aggregate?

3. Why pass structs? (not struct pointers)

4. CFile not working properly, can't figure out why

5. Why am I not getting correct position?

6. Why am I not intercepting Enter key (VK_RETURN)

7. Why am I not getting a LIB?

8. Why affecting volatile struct does not compile ?

9. NetShareGetInfo() - why does this simple program not work?

10. Why does simple inheritance from CTabCtrl not work???

11. Help, I am new to cprograming and can't figure out why this does not work right. - mail.cpp (0/1)

12. Help, I am new to cprograming and can't figure out why this does not work right. - mail.cpp (0/1)

 

 
Powered by phpBB® Forum Software