terms of importance

Discussion in 'C++' started by eas, Jan 17, 2004.

  1. eas

    eas Guest

    Are the following comments all correct? Thanks in advance!

    /*declaration and definition of myconst?*/
    const int myconst = 4567;

    /*declaration of myclass only?*/
    class myclass;

    /*definition of myclass?*/
    class myclass
    {
    /*definition of mystatic?*/
    static int mystatic;
    /*declaration?*/
    void mymethod();
    };

    /*initialization of mystatic?*/
    int myclass::mystatic = 7890;

    /*definition of mymethod?*/
    void myclass::mymethod() { ... }


    int main()
    {
    /*delcaration and definition of myobject?*/
    myclass myobject;
    return 0;
    }
    eas, Jan 17, 2004
    #1
    1. Advertising

  2. eas wrote:
    >
    > Are the following comments all correct? Thanks in advance!
    >
    > /*declaration and definition of myconst?*/
    > const int myconst = 4567;
    >
    > /*declaration of myclass only?*/
    > class myclass;
    >
    > /*definition of myclass?*/
    > class myclass
    > {
    > /*definition of mystatic?*/
    > static int mystatic;
    > /*declaration?*/
    > void mymethod();
    > };
    >
    > /*initialization of mystatic?*/
    > int myclass::mystatic = 7890;
    >
    > /*definition of mymethod?*/
    > void myclass::mymethod() { ... }
    >
    > int main()
    > {
    > /*delcaration and definition of myobject?*/
    > myclass myobject;
    > return 0;
    > }


    It seems to me you're right...

    -------------------------------------
    #error in operator: add beer
    Simon Bachmann, Jan 17, 2004
    #2
    1. Advertising

  3. "eas" <> wrote...
    > Are the following comments all correct? Thanks in advance!
    >
    > /*declaration and definition of myconst?*/
    > const int myconst = 4567;


    declaration, definition, _and_ initialisation.

    >
    > /*declaration of myclass only?*/
    > class myclass;


    Also known as "forward-declaration".

    >
    > /*definition of myclass?*/
    > class myclass
    > {
    > /*definition of mystatic?*/
    > static int mystatic;


    No, declaration of 'mystatic'.

    > /*declaration?*/
    > void mymethod();


    Yes. Most of the things inside a class definition are declarations.

    > };
    >
    > /*initialization of mystatic?*/
    > int myclass::mystatic = 7890;


    No, _definition_ _and_ initialisation of myclass::mystatic.

    >
    > /*definition of mymethod?*/
    > void myclass::mymethod() { ... }


    Yes.

    >
    >
    > int main()
    > {
    > /*delcaration and definition of myobject?*/
    > myclass myobject;


    Yes.

    > return 0;
    > }
    >
    >


    HTH

    V
    Victor Bazarov, Jan 17, 2004
    #3
  4. eas wrote:
    > Are the following comments all correct? Thanks in advance!
    >
    > /*declaration and definition of myconst?*/
    > const int myconst = 4567;


    Yes.

    > /*declaration of myclass only?*/
    > class myclass;


    Yes.

    > /*definition of myclass?*/
    > class myclass


    Yes.

    > {
    > /*definition of mystatic?*/
    > static int mystatic;


    No. This is declaration.

    > /*declaration?*/
    > void mymethod();


    Yes.

    > };
    >
    > /*initialization of mystatic?*/
    > int myclass::mystatic = 7890;


    It is definition of 'myclass::mystatic'. It also contains an initializer.

    > /*definition of mymethod?*/
    > void myclass::mymethod() { ... }


    Yes.

    > int main()
    > {
    > /*delcaration and definition of myobject?*/
    > myclass myobject;


    Yes. It is sufficient to say that this is definition of 'myobject'.

    > return 0;
    > }


    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Jan 17, 2004
    #4
  5. Victor,

    "Victor Bazarov" <> wrote in message
    news:KkgOb.76758$nt4.108224@attbi_s51...
    > "eas" <> wrote...
    > > Are the following comments all correct? Thanks in advance!
    > >
    > > /*declaration and definition of myconst?*/
    > > const int myconst = 4567;

    >
    > declaration, definition, _and_ initialisation.
    >
    > >
    > > /*declaration of myclass only?*/
    > > class myclass;

    >
    > Also known as "forward-declaration".
    >
    > >
    > > /*definition of myclass?*/
    > > class myclass
    > > {
    > > /*definition of mystatic?*/
    > > static int mystatic;

    >
    > No, declaration of 'mystatic'.
    >
    > > /*declaration?*/
    > > void mymethod();

    >
    > Yes. Most of the things inside a class definition are declarations.


    Can you give the examples of when things inside a class definition
    are not declarations?

    --The Direvtive

    > > };
    > >
    > > /*initialization of mystatic?*/
    > > int myclass::mystatic = 7890;

    >
    > No, _definition_ _and_ initialisation of myclass::mystatic.
    >
    > >
    > > /*definition of mymethod?*/
    > > void myclass::mymethod() { ... }

    >
    > Yes.
    >
    > >
    > >
    > > int main()
    > > {
    > > /*delcaration and definition of myobject?*/
    > > myclass myobject;

    >
    > Yes.
    >
    > > return 0;
    > > }
    > >
    > >

    >
    > HTH
    >
    > V
    >
    >





    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
    The Directive, Jan 19, 2004
    #5
  6. eas

    Rolf Magnus Guest

    The Directive wrote:

    >> Yes. Most of the things inside a class definition are declarations.

    >
    > Can you give the examples of when things inside a class definition
    > are not declarations?


    Depends on what you define as 'thing', but e.g.

    public:

    is not a delcaration.
    Rolf Magnus, Jan 19, 2004
    #6
  7. "The Directive" <> wrote...
    > Victor,
    >
    > "Victor Bazarov" <> wrote in message
    > news:KkgOb.76758$nt4.108224@attbi_s51...
    > > "eas" <> wrote...
    > > > Are the following comments all correct? Thanks in advance!
    > > >
    > > > /*declaration and definition of myconst?*/
    > > > const int myconst = 4567;

    > >
    > > declaration, definition, _and_ initialisation.
    > >
    > > >
    > > > /*declaration of myclass only?*/
    > > > class myclass;

    > >
    > > Also known as "forward-declaration".
    > >
    > > >
    > > > /*definition of myclass?*/
    > > > class myclass
    > > > {
    > > > /*definition of mystatic?*/
    > > > static int mystatic;

    > >
    > > No, declaration of 'mystatic'.
    > >
    > > > /*declaration?*/
    > > > void mymethod();

    > >
    > > Yes. Most of the things inside a class definition are declarations.

    >
    > Can you give the examples of when things inside a class definition
    > are not declarations?


    Yes, I can. Oh, did you mean to ask me to give such example?

    class A {
    class Nested {
    int a;
    };
    };

    The 'Nested' is a _definition_ inside the class A definition. More?

    class A {
    enum E { A, B, C };
    };

    'A', 'B', and 'C' are _definitions_ of enumerators inside the class A
    definition.

    Of course, one can have a member function _defined_ right there, in
    a class definition, but you already knew that...

    Victor
    Victor Bazarov, Jan 19, 2004
    #7
  8. Victor Bazarov wrote:
    >> ...
    >> Can you give the examples of when things inside a class definition
    >> are not declarations?

    >
    > Yes, I can. Oh, did you mean to ask me to give such example?
    >
    > class A {
    > class Nested {
    > int a;
    > };
    > };
    >
    > The 'Nested' is a _definition_ inside the class A definition. More?
    >
    > class A {
    > enum E { A, B, C };
    > };
    >
    > 'A', 'B', and 'C' are _definitions_ of enumerators inside the class A
    > definition.
    >
    > Of course, one can have a member function _defined_ right there, in
    > a class definition, but you already knew that...
    > ...


    Yes, but formally speaking the definitions given in your examples are
    both definitions and declarations at the same time, while it appears
    that the previous poster was looking for something that is not a
    declaration. Although it could be just a bad wording on his part...

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Jan 19, 2004
    #8
  9. "Andrey Tarasevich" <> wrote...
    > Victor Bazarov wrote:
    > >> ...
    > >> Can you give the examples of when things inside a class definition
    > >> are not declarations?

    > >
    > > Yes, I can. Oh, did you mean to ask me to give such example?
    > >
    > > class A {
    > > class Nested {
    > > int a;
    > > };
    > > };
    > >
    > > The 'Nested' is a _definition_ inside the class A definition. More?
    > >
    > > class A {
    > > enum E { A, B, C };
    > > };
    > >
    > > 'A', 'B', and 'C' are _definitions_ of enumerators inside the class A
    > > definition.
    > >
    > > Of course, one can have a member function _defined_ right there, in
    > > a class definition, but you already knew that...
    > > ...

    >
    > Yes, but formally speaking the definitions given in your examples are
    > both definitions and declarations at the same time, while it appears
    > that the previous poster was looking for something that is not a
    > declaration. Although it could be just a bad wording on his part...


    I seem unable to think of a definition that is _not_ simultaneously
    a declaration. Can you name a couple? Thanks.

    V
    Victor Bazarov, Jan 19, 2004
    #9
  10. "Victor Bazarov" <> wrote in message
    news:XoKOb.81860$Rc4.294424@attbi_s54...
    > "Andrey Tarasevich" <> wrote...


    > >
    > > Yes, but formally speaking the definitions given in your examples

    are
    > > both definitions and declarations at the same time, while it

    appears
    > > that the previous poster was looking for something that is not a
    > > declaration. Although it could be just a bad wording on his

    part...
    >
    > I seem unable to think of a definition that is _not_ simultaneously
    > a declaration. Can you name a couple? Thanks.
    >


    How about

    void dog::bark() { std::cout << "woof!\n"; }

    Jonathan
    Jonathan Turkanis, Jan 19, 2004
    #10
  11. Victor Bazarov wrote:
    >> ...

    > I seem unable to think of a definition that is _not_ simultaneously
    > a declaration. Can you name a couple? Thanks.
    > ...


    I don't think I can, especially if we take into account the fact that
    the defition of the term "definition" in the standard (3.1/2) begins
    with "A 'declaration' is a 'definition' unless ..."

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Jan 19, 2004
    #11
  12. Jonathan Turkanis wrote:
    >> > Yes, but formally speaking the definitions given in your examples

    > are
    >> > both definitions and declarations at the same time, while it

    > appears
    >> > that the previous poster was looking for something that is not a
    >> > declaration. Although it could be just a bad wording on his

    > part...
    >>
    >> I seem unable to think of a definition that is _not_ simultaneously
    >> a declaration. Can you name a couple? Thanks.
    >>

    >
    > How about
    >
    > void dog::bark() { std::cout << "woof!\n"; }
    > ...


    From the formal point of view, this is still a declaration. 7.1 refers
    to 'function-definition' as one form of declaration. And
    'function-definition' includes definitions of both standalone functions
    and and member functions. Of course, this is not a self-sufficient
    declaration, meaning that the function must also be declared in the
    class definition, but declaration nevertheless.

    --
    Best regards,
    Andrey Tarasevich
    Andrey Tarasevich, Jan 19, 2004
    #12
  13. "Andrey Tarasevich" <> wrote in message
    news:...
    > Jonathan Turkanis wrote:


    > >> I seem unable to think of a definition that is _not_

    simultaneously
    > >> a declaration. Can you name a couple? Thanks.
    > >>

    > >
    > > How about
    > >
    > > void dog::bark() { std::cout << "woof!\n"; }
    > > ...

    >
    > From the formal point of view, this is still a declaration. 7.1

    refers
    > to 'function-definition' as one form of declaration. And
    > 'function-definition' includes definitions of both standalone

    functions
    > and and member functions. Of course, this is not a self-sufficient
    > declaration, meaning that the function must also be declared in the
    > class definition, but declaration nevertheless.
    >


    Yeah, you got me. :( The standard implicitly states that all
    definitions are declarations in 3.1/2.

    Okay, I'll give it one last try:

    #define THIS_IS_A_DIRECTIVE but also a definition ;-)

    Jonathan
    Jonathan Turkanis, Jan 19, 2004
    #13
  14. "The Directive" <> wrote in message
    news:...
    >
    > Can you give the examples of when things inside a class definition
    > are not declarations?


    Implicit inline functions for one:

    class C
    {
    int f() { return 101; } // <- definition
    };


    - Risto -
    Risto Lankinen, Jan 19, 2004
    #14
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    473
    Darryl L. Pierce
    Jan 30, 2006
  2. Vishnu

    newbie:importance of XML?

    Vishnu, Dec 22, 2003, in forum: XML
    Replies:
    1
    Views:
    917
    Patrick TJ McPhee
    Dec 22, 2003
  3. ASP.NET
    Replies:
    1
    Views:
    2,307
    Patrice
    Jul 17, 2006
  4. Amarendra GODBOLE
    Replies:
    25
    Views:
    685
    Dan Pop
    Jan 21, 2004
  5. Doug Tolton
    Replies:
    1
    Views:
    332
    Doug Tolton
    Aug 13, 2003
Loading...

Share This Page