Berkeley CSUA MOTD:Entry 17795
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2024/11/23 [General] UID:1000 Activity:popular
11/23   

2000/3/18-20 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Java] UID:17795 Activity:high
3/18    Rookie C++ question: Is the following circular situation allowed -
        defining a ClassA with a member variable that is a pointer to an
        object of ClassB, and also defining ClassB with a member variable that
        is pointer to an object of ClassA.  If it is allowed, how do I go
        about with the #include, #ifndef, etc.
        \_ not to forget to mention that many data-structs use this
           circular pointer of classes of different types (red-black trees)
           so it wouldn't make sense to design one of the most versatile
           languages without this feature.
        \_ Yes, it's allowed.  You need to do a forward declaration for the
           classes that haven't been defined at the point where you're using
           them.  For example:
                // A.h
                class ClassB;
        No preprocessor pain is necessary.  This works for reference members
        as well. And they don't have to be in separate files.... This works
        too:
                class ClassA {  ClassB *pB; };
                // B.h
                class ClassA;
        Good luck... -mogul
                class ClassB {  ClassA *pA; };
           No preprocessor pain is necessary.  This works for reference
           members as well. And they don't have to be in separate files....
           This works too:
                class ClassB;
                class ClassA { ClassB *pB; };
                class ClassB { ClassA *pA; };
           Good luck... and sign your frickin' name, punk! -mogul
           \_ Hehehe!  Thanks for the answer!  It's kind of embarassing
              to put my name when it's such a dumb question.  I know
              there is function declaration, but didn't know about
              class declaration, having always used the #include, #ifndef
              stuff.
           \_ real men use "typename" for forward decls. or something. -ali
              \_ Whatever.  Real men know when to use typename.  And that's in
                 template functions and classes when the type name might not be
                 easily derived as such.
              \_ real men use real languages that don't have this sort of BS.
2024/11/23 [General] UID:1000 Activity:popular
11/23   

You may also be interested in these entries...
2012/7/19-11/7 [Computer/SW/Languages/C_Cplusplus] UID:54439 Activity:nil
7/19    In C or C++, how do I write the code of a function with variable
        number of parameters in order to pass the variable parameters to
        another function that also has variable number of parameters?  Thanks.
        \_ The usual way (works on gcc 3.0+, Visual Studio 2005+):
               #define foo(fmt, ...) printf(fmt, ##__VA_ARGS__)
           The cool new way (works on gcc 4.3+):
	...
2004/10/29-30 [Computer/SW/Languages/C_Cplusplus] UID:34449 Activity:very high
10/29   C++ is so freaking BROKEN.  Augh!
        \_ Just use C.
           \_ Would if I could.
        \_ No, you are.  C++ works just fine, and far better than C for many
           purposes.
           \_ C vs. C++.  FIGHT!!!
	...
2004/4/13-14 [Computer/SW/Languages/C_Cplusplus] UID:13175 Activity:high
4/13    How much C++/C knowledge do recent Berkeley CS/EECS grad have?
        \_ Class CSGrad inherits FromDaddy and does not implement C++Knowledge
           very well.
           \_ funny.  just the rich and poor as always.  the middle class can't
              afford education.
        \_ They know how to deal with pointers and addresses, malloc and free.
	...
2004/3/30-31 [Computer/SW/Languages/Perl] UID:12925 Activity:kinda low
3/17    In Perl, how do I make variables have static types and type check
        for valid parameter/actuals? I realize that variables are untyped
        in Perl ($var can be 0.001 or "hello") but I'd like to have more
        strict checking so that errors would be caught ahead of run-time,
        Thanks,                                                 -java guy
        \_ use java.  Seriously.  You don't use perl if you want strong
	...
2002/11/5 [Computer/SW/Languages/C_Cplusplus] UID:26409 Activity:high
11/4    I'm having a problem formatting inline elements in xsl-- I have to
        handle the situation where
        <school>I graduated from
          <link href="<DEAD>www.berkeley.edu"<DEAD>Cal</link> in 1998.
        </school>
        My current template is like this:
	...
2000/11/21 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Java] UID:19871 Activity:very high
11/21   All java class inherites from class *Object*, if I have three classes
        A, B, and C all have one same method showErr().  If I want to have a
        function that can call showErr() depending on the object that I passed
        in, eg.
                public void handleErr(Object o) {
                        o.showErr();
	...
2013/5/1-18 [Computer/SW/Languages/Java, Computer/Theory] UID:54669 Activity:nil
5/1     What's the difference between CS and Computer Engineering?
        http://holykaw.alltop.com/top-ten-paying-degrees-for-college-graduates
        \_ One is science and the other is engineering.
        \_ From http://en.wikiquote.org/wiki/Computer_science
           'A folkloric quotation ... states that "computer science is no more
           about computers than astronomy is about telescopes."  The design
	...
2012/12/4-18 [Computer/SW/Languages/Java] UID:54544 Activity:nil
12/4    Holy cow, everyone around me in Silicon Valley is way beyond
        middle class according to Chinni's definition:
        http://en.wikipedia.org/wiki/American_middle_class
        \_ Let's set our goals higher:
           http://en.wikipedia.org/wiki/Upper_middle_class_in_the_United_States
           \_ How about this one?
	...
2012/10/29-12/4 [Science/Disaster, Computer/SW/Languages/Java, Politics/Domestic/President/Bush] UID:54516 Activity:nil
10/29   Go Away Sandy.
        \_ Sorry, Coursera is performing preventive maintenance for this
           class site ahead of Hurricane Sandy. Please check back in 15 minutes.
           class site ahead of Hurricane Sandy. Please check back in 15
           minutes.
        \_ Bitch.
	...
2012/1/18-3/3 [Computer/SW/Languages/Java, Finance/Investment] UID:54290 Activity:nil
1/18    I own a bunch of NFLX stocks bought at several different periods
        (from high $200 all the way down to $80). I dumped a few and
        still have a few. Why the hell is Reid Hastings still making
        $500,000/year? How do I join the pending NFLX Class Action
        Lawsuit?
        \_ Why would you buy stock in a company run by a narcissistic
	...