Live data from Hacker News

My Most Important C++ Aha Moments (2006)

artima.com

1–10 of 84 posts

Re: My Most Important C++ Aha Moments (2006)

#6
post #3

I love C and Objective-C. I can't stand C++. Is that common among programmers?

What has always bugged me about C++, but maybe I am overlooking some reason why this generally cannot work, is that it does not resolve circular dependencies such as this one:

    // file: A.h
    class A {
      B* _b;
    };
    
    // file: B.h
    class B {
      A* _a;
    };
I mean a pointer has a fixed size, so couldn't the compiler just leave some sort of type placeholder in class A until class B is eventually defined.

Re: My Most Important C++ Aha Moments (2006)

#7
post #6
post #3

I love C and Objective-C. I can't stand C++. Is that common among programmers?

What has always bugged me about C++, but maybe I am overlooking some reason why this generally cannot work, is that it does not resolve circular dependencies such as this one: // file: A.h class A { B* _b; }; // file: B.h class B { A* _a; }; I mean a pointer has a fixed size, so couldn't the compiler just leave some sort of type placeholder in class A until class B is eventually defined.

This can be done, check the end of this answer: http://stackoverflow.com/a/628079/429972

   // file: A.h
   class B;
   class A {
     B* _b; // or any of the other variants.
   };

Re: My Most Important C++ Aha Moments (2006)

#8
post #7
post #6

Earlier quoted context omitted.

What has always bugged me about C++, but maybe I am overlooking some reason why this generally cannot work, is that it does not resolve circular dependencies such as this one: // file: A.h class A { B* _b; }; // file: B.h class B { A* _a; }; I mean a pointer has a fixed size, so couldn't the compiler just leave some sort of type placeholder in class A until class B is eventually defined.

This can be done, check the end of this answer: http://stackoverflow.com/a/628079/429972 // file: A.h class B; class A { B* _b; // or any of the other variants. };

You can also do this

    class A {
      class B* _b;
    };

Re: My Most Important C++ Aha Moments (2006)

#9
post #3

I love C and Objective-C. I can't stand C++. Is that common among programmers?

C programmer here; I don't like C++ much because every library tends to reinvent the whole stack (or maybe that's just my impression from using MFC and Qt, which are notorious in that regard).

RAII and scope based construction/destruction is actually quite nice.

Post reply on HN