C++ violates, what does it mean?

This is a discussion on C++ violates, what does it mean? within the Tech Board forums, part of the Community Boards category; Originally Posted by http://www.adahome.com/Resources/Languages/contrast_ada_cpp.html C++ violates the separation of contract and implementation when inline functions are declared. Ada does not. ...

  1. #1
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231

    Question C++ violates, what does it mean?

    Quote Originally Posted by http://www.adahome.com/Resources/Languages/contrast_ada_cpp.html
    C++ violates the separation of contract and implementation when inline functions are declared.
    Ada does not.
    What does it mean?
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  2. #2
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,532
    This is a class contract:
    Code:
    class X {
      public:
        X(int);
        ~X();
        int foo();
        int get_int();
        void set_int();
      private:
        int x;
    };
    Say for example that I wanted to inline foo(), for some reason. I could define the function in the class contract to achieve that; therefore, I've violated a common style guideline that states you should keep implementation of a class and definition of a class separate. I find it a weak argument, but that's me.

    In fact the whole way that page makes its point bothers me.
    Last edited by whiteflags; 09-15-2006 at 04:08 AM.

  3. #3
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    In fact the whole way that page makes its point bothers me.
    Of course it is Ada site. ;-)
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  4. #4
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Portugal
    Posts
    7,383
    Particularly considering we can still define the function outside the class body. Inlined or not.

    Besides...

    55. C++ is widely used.
    Ada is not.
    The programmer’s wife tells him: “Run to the store and pick up a loaf of bread. If they have eggs, get a dozen.”
    The programmer comes home with 12 loaves of bread.


    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  5. #5
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,532
    C++ does that! Ada does this!
    <unstated>And Ada must be better because of this!</unstated> Okay, but write something the critical reader can appreciate.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,344
    > C++ violates the separation of contract and implementation when inline functions are declared.
    That's the least of the problems - the fact that C++ classes have to list their private parts in the class for all the world to see should be more of a concern.

    I suppose you could do this
    Code:
    class foo_private;
    class foo {
      public:
        foo();
        ~foo();
      private:
        foo_private *private;
    };
    Where only foo.cpp implementation files get to include foo_private.h and all the things it offers.

    On the plus side, this may help to stop rebuild cascades when you change some base class and EVERYTHING has to be rebuilt because of it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    20,981
    That "Comparison of Ada and C++ Features" was done before C++ was standardised, so it is out of date.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    Quote Originally Posted by Salem
    I suppose you could do this
    Also known as the PIMPL idiom and widely used.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21