Berkeley CSUA MOTD:Entry 21134
Berkeley CSUA MOTD
 
WIKI | FAQ | Tech FAQ
http://csua.com/feed/
2025/05/24 [General] UID:1000 Activity:popular
5/24    

2001/4/29-30 [Computer/SW/Languages/C_Cplusplus, Computer/SW/Languages/Java] UID:21134 Activity:very high
4/28    I haven't really use C++ in the last 3 years.  Can someone remind me
        how to initialize a dynamic array of template class pointers?

            class Bar;
            template<class T> class Foo;

            //
            // Is this the right way to initialize this:
            //       ---
            //    -> | | -> Bar
            //       ---
            //       | | -> Bar
            //       ---
            //       | | -> Bar
            //       ---
            //        .
            //        .
            //        .
            //
            Foo<Bar> **barArrayOfFooPtr;

            int size = 5;

            //
            // Forgot how to initialize the following line correctly.
            //
            // barArrayOfFooPtr = new Foo<string>* [size];
            //                    \_ Since you just want an array of pointers,
            //                       try Foo<string>*
            barArrayOfFooPtr = ???

            for (int i = 0; i < size; i++)
            {
              barArrayOfFooPtr[i] = new Foo<string>;
            }                                 \_ Try "new Foo<Bar>"
                                                 \_ Typo.  I do have Foo<Bar>.

        does not seem to be the correct way of doing it.
        \_ the right way to do what you're trying to do is:
           vector<Foo<Bar>*> arrayOfFoos(number_of_elements);
           most other ways are flawed in many ways. -ali
           \_ Correct answer moved to the top.
        \_ Compiler Error message please.
           \_ The problem is I forgot how to initialize a dynamic array of
               class pointers.  I remember that a static array of class
        \_ the right way to do what you're trying to do is:
           vector<Foo<Bar>*> arrayOfFoos(number_of_elements);
           most other ways are flawed in many ways. -ali
               template pointers can be initialzed as
                 Foo<Bar> *barArrayOfFooPtr = new Foo<Bar>[10];
               but I forgot how to initialize a dynamic one.
        \_ Try Foo<string> **barArrayOfFooPtr; .
2025/05/24 [General] UID:1000 Activity:popular
5/24    

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
	...