sg

Salı, Ocak 03, 2006

[lug] Re: Reagarding structures


Adam,

It is working absolutely fine when I decalred and defined
outside the main.
I am having certain doubts about this program..........if it is
possible could U clarify me?
I declared and defined the struct varaible in inside the main,
If I passing from the main why I am unable to access it ?is
there any specific reason

Rgrds
Sunil
On 1/3/06, Adam Visegradi <a.visegradi@gmail.com> wrote:
> Probably because struct test is inside main().
>
> "from 'struct main::test [5]' to 'struct test []'" //notice the `main::'
> and
> "error C2027: use of undefined type 'test'"
>
> Try this:
> void func(struct main::test x[]);
> or define struct test {} globally.
>
> It's just a guess, but I hope it helps.
>
> Nice day! :)
>
> On 1/3/06, sunil vvn <sunil.vvn@gmail.com> wrote:
> >
> > Hi All,
> >
> > Could U anybody suggest me why this is throwing error,plz
> > rectify me where I am going wrong.
> >
> > #include<stdio.h>
> > void func(struct test x[]);
> > int main()
> > {
> >
> > struct test
> > {
> > int y;
> > };
> > struct test x[] = {20,30,40,50,60};
> > func(x);
> > return 0;
> > }
> >
> > void func(struct test x[])
> > {
> > int mid = 2;
> >
> > printf("%d\n",x[mid].y );
> >
> > }
> >
> > I got the following errors when I execute in the vc++ editor
> >
> > --------------------Configuration: test - Win32 Debug--------------------
> > Compiling...
> > test.cpp
> > E:\sunil\fiscus\test\test.cpp(11) : error C2664: 'func' : cannot
> > convert parameter 1 from 'struct main::test [5]' to 'struct test []'
> > Types pointed to are unrelated; conversion requires
> > reinterpret_cast, C-style cast or function-style cast
> > E:\sunil\fiscus\test\test.cpp(19) : error C2036: 'struct test []' :
> unknown size
> > E:\sunil\fiscus\test\test.cpp(19) : error C2027: use of undefined type
> 'test'
> > E:\sunil\fiscus\test\test.cpp(2) : see declaration of 'test'
> > E:\sunil\fiscus\test\test.cpp(19) : error C2228: left of '.y' must
> > have class/struct/union type
> > Error executing cl.exe.
> >
> > test.obj - 4 error(s), 0 warning(s)
> >
> > -----------------------------------
> >
> > Regrads
> > Sunil
> >
>
>
>
> --
> Visegradi Adam
>

0 Comments:

Yorum Gönder

<< Home


Komik Videolar   islam  şarkı sözleri  yemek tarifleri  gelibolu  huzur   sağlık