Please please help a newbie!! 
Author Message
 Please please help a newbie!!


Quote:
>Hi there!

>It's quite embarrassing to ask those two questions, because they seem
>absolutely stupid (they probably are). Yesterday I started to learn C/C++. I
>bought a 700 pages book with a cd included that has two compilers on it). I
>fully understand the chapter about the types, but the things I program just
>can't be compiled. I extracted the following two problems:

>----------- example 1: -------------
>int i;
>int & a=i;

>main() {
>}
>--------------------------------------------

In the above example, '&' is not a data type, it is an operator.
If you want a integer pointer to 'i' you need to do the following:

int i, *a;

main(){
   a = &i;

Quote:
}

>This is not compiled, I get the following output with  Symantec C++ 6.11:

>D:\SC>sc test1.c        

>sccx test1.c
>int & a=i;
>    ^
>test1.c(2) : Error: '=', ';' or ',' expected

>--- errorlevel 1

>The second thing that doesn't work is this:

>----------- example 2: -------------
>struct abc {
>  int i;
>  char a;
>  void f1() {
>  };
>};

>main() {
>}
>---------------------------------------------

In the example above, you cannot define a function in the body of a
struct.  If you want a pointer to a function, you need to do the following:

struct abc{
   int i;
   char a;
   void (*f1)();  /* This reads as "f1 a pointer to a function returning void" */

Quote:
};

main() {
Quote:
}


- Show quoted text -

Quote:
>This isn't compiled either, here's the output:

>D:\SC>sc test2.c

>sccx test2.c
>  void f1() {
>            ^
>test2.c(4) : Error: illegal type for 'f1' member

>--- errorlevel 1

>Before you think I'm absolutely stupid... I used to be very good at Pascal
>(TP 6.0), and I'm also experienced in OOP under Pascal. I have no clue of
>C++, however, and I can only rely on what's written in that book. Apparently
>it doesn't tell me the truth, does it?

>Can you please help me with those two problems (referenced variable and
>function within a class), so that I can go on and learn a few more difficult
>things?

>Thanks in advance,


>=================================================================
>Summer's day, as she passed away. Birds were singing in the
>summer sky; then came the rain, and once again, a tear fell
>from her mother's eye...
>=================================================================



Mon, 03 Aug 1998 03:00:00 GMT  
 Please please help a newbie!!

)Hi there!
)
)It's quite embarrassing to ask those two questions, because they seem
)absolutely stupid (they probably are). Yesterday I started to learn C/C++. I
)bought a 700 pages book with a cd included that has two compilers on it). I
)fully understand the chapter about the types, but the things I program just
)can't be compiled. I extracted the following two problems:
)
)----------- example 1: -------------
)int i;
)int & a=i;
     ^ If you are trying to declare a pointer to
       an integer, and set it to point to i, then you need this line:

        int     *a = &i;

)main() {
)}

[error results cut]

)The second thing that doesn't work is this:
)
)----------- example 2: -------------
)struct abc {
)  int i;
)  char a;
)  void f1() {
        ^ If you are trying to declare a pointer
          to a function returning void, then you need
                void    *f1();
          no "{}" are needed.
)  };
)};
)
)main() {
)}

[errors cut]

)Before you think I'm absolutely stupid... I used to be very good at Pascal

Not stupid, just ignorance. And ignorance, like epoxy, can be cured
(there is no cure for stupidity).

Mike
----
char *p="char *p=%c%s%c;main(){printf(p,34,p,34);}";main(){printf(p,34,p,34);}

I don't speak for DSC.         <- They make me say that.



Mon, 03 Aug 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Please please help a newbie!!

2. Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!Please help!!!!

3. Please help!!!!Please help!!!!Please help!!!!

4. help: Guru needed please please please

5. HELP please on QUEUES!! please, please, please, please,please...

6. PLEASE PLEASE PLEASE PLEASE

7. NEED HELP WITH PRITING AN ARRAY, PLEASE PLEASE HELP

8. PLEASE PLEASE HELP HELP...question on interleaving C functions

9. Help C newbie need help please

10. Help C newbie need help please

11. HELP on ATL with VC7 - newbie please help...

12. Please Please Help!!!!!!

 

 
Powered by phpBB® Forum Software