Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

C++ Simple testing

Name: Anonymous 2009-01-20 10:48

Sup /prog/, where's the mistake?

class ArrayBox
{
public:

int numbers[9];
//functions
};

int main()
{
ArrayBox ab;
ab.numbers[] = {12, 23, 43, 4, 15, 61, 79, 18, 9, 5};
}


u2.cpp: In function "int main()":
u2.cpp:94: Error: expected primary-expression before "]" token
u2.cpp:94: Error: expected primary-expression before "{" token
u2.cpp:94: Error: expected ";" before "{" token


isn't that the right syntax to fill an array? I'm confused.

Name: Anonymous 2009-01-20 10:49

Disregard that one should normally use setter methods and / or user input for filling the array, etc etc.

Name: Anonymous 2009-01-20 10:59

Okay I just found at that I can only fill an array like that while initializing. /thread over

Name: Anonymous 2009-01-20 11:00

A Sepples way!


    ArrayBox ab;
   
    ab.setItem(0, 12);
    ab.setItem(1, 23);
    ab.setItem(2, 43);
    ab.setItem(3, 4);
    ab.setItem(4, 15);
    ab.setItem(5, 61);
    ab.setItem(6, 79);
    ab.setItem(7, 18);
    ab.setItem(8, 9);
    ab.setItem(9, 5); /* lol */

Name: Anonymous 2009-01-20 11:01

HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]
HAY FAGGIT, LEARN C
[spoiler[HAY FAGGIT, LEARN C[/spoiler]

Name: Anonymous 2009-01-20 11:11

>>5
BBCode newbie

Name: Anonymous 2009-01-20 11:47

If you use C++, use STL, don't reinvent the wheel.

For example, use vector if you require fast random access, or lists if you require fast insertions.

For example, vector.


vector<int> numbers; // create vector with element type int
numbers.reserve(10); // reserve memory for 10 elements, optional
for (int i = 0; i < 10; i++)
    numbers[i] = i; // or push_back(i)

Name: Anonymous 2009-01-20 11:49

>>7
As a note, reserve is NOT optional if you use the [] operator to add elements, it's only optional if you use push_back(), because push_back() automatically reserves more space.

Although it's more efficient to reserve space for 10 elements and then use push_back to add the numbers.

Name: Anonymous 2009-01-20 12:08

>>4
No, that's the VB way

Name: Anonymous 2009-01-20 12:40

>>7
vector<int> numbers;
numbers.reserve(10);


At the second line it gives me the error

ISO-C++ prohibits declaration of "numbers" without a type.
Expected ";" before "." token.


Yes, I included <vector>.

Name: Anonymous 2009-01-20 13:11

Never mind, I alredy got it.
Now just a convention question. Should I make seperate .cpp files for seperate classes? Until now I've only done stuff with 2 classes, I just wrote it down in one cpp file. Should I create own cpp files for every class, like in Java or is it okay to leave it like that?

Name: Anonymous 2009-01-20 13:29

>>11
up to you. But if you've got loads, then it's best to start factoring things up.

Name: Anonymous 2009-01-20 13:59

>>9
Show me the sepples way then. I want to have an array with elements {12, 23, 43, 4, 15, 61, 79, 18, 9, 5};

Name: Anonymous 2009-01-20 14:08

>>8
Actually when you use the [] operator to add elements you need to call resize. In >>7 after he calls reserve the size of the vector is still zero, so you can't use the [] operator. It's better to use push_back when you want to add elements to a vector.

Name: Anonymous 2009-01-20 14:20

>>13
template<typename T, size_t N>
vector<T> vector_from_array(T (&a)[N]) {
    return vector<T>(a, a + N);
}


int a[] = { 12, 23, 43, 4, 15, 61, 79, 18, 9, 5};
vector<int> v = vector_from_array(a);

Name: Anonymous 2009-01-20 14:25

C++ is an octopus made by nailing extra legs onto a dog

Name: Anonymous 2009-01-20 14:30

Haskell is an octopus made by nailing extra legs onto a copy of a dead lazy dog

Sorry, Haskell's owner, I couldn't resist. If it's any consolation, I do feel kind of bad about it :(, in fact, I feel Terrible!

Name: Anonymous 2009-01-20 14:46

>>15
hahaha, oh wow

Name: Anonymous 2009-01-20 15:38

>>13
Wouldn't that be just
int numbers[] = {12, 23, 43, 4, 15, 61, 79, 18, 9, 5};

Name: Anonymous 2009-01-20 15:57

Name: Anonymous 2009-01-20 16:00

Historically, languages designed for other people to use have been bad: Cobol, PL/I, Pascal, Ada, C++. The good languages have been those that were designed for their own creators: C, Perl, Smalltalk, Lisp

Name: Anonymous 2009-01-20 16:10

>>20
Also available in sex toy format:
http://i43.tinypic.com/2ypbux1.jpg

Name: Anonymous 2009-01-20 16:13

>>21
Didn't Bjarne design Sepples for himself? Lisp was designed for no one to use, and once they realized people wanted it, they never planned for people to use sexps. I'm pretty sure Alan Kay mostly wanted other people to use Smalltalk, since he wasn't the hugest of programmers himself.

Name: Anonymous 2009-01-20 16:13

>>22
I lol and :( everytime someone posts that pic

Name: Anonymous 2009-01-20 16:13

hugest

Name: Anonymous 2009-01-20 16:16

>>23
Alan Kay designed Smallkalk to be used by kids.

Name: Anonymous 2009-01-20 16:18

>>26
Kids designed Smalltalk to be used by Alan Kay.

Name: Anonymous 2009-01-20 16:19

Smalltalk designed kids to be used by Alen Key

Name: Anonymous 2009-01-20 16:42

Small Kay designed Alan kids to be used by talk.

Name: Anonymous 2009-01-20 16:43

Anal Key talked to designers to use small kids.

Name: Anonymous 2009-01-20 16:50

[b][u][o]ANAL KEY WILL BEFRIEND ANAL TOURING IN HELL, WHERE THEY SHALL ABUSE SMALL KIDS[/u][/u][/b]

Name: Anonymous 2009-01-20 16:52

Alan Key is to Smalltalk what Steve Jobs is to apple, only faggier and much poorer.

Name: Anonymous 2009-01-20 16:53

>>32
faggier
hardly

Name: Anonymous 2009-01-21 0:02

>>31
Please don't make troll posts!

Name: Anonymous 2009-01-21 4:00

C++ is a horrible language. It's made more horrible by the fact that a lot
of substandard programmers use it, to the point where it's much much
easier to generate total and utter crap with it. Quite frankly, even if
the choice of C were to do *nothing* but keep the C++ programmers out,
that in itself would be a huge reason to use C.

In other words: the choice of C is the only sane choice. I know Miles
Bader jokingly said "to piss you off", but it's actually true. I've come
to the conclusion that any programmer that would prefer the project to be
in C++ over C is likely a programmer that I really *would* prefer to piss
off, so that he doesn't come and screw up any project I'm involved with.

C++ leads to really really bad design choices. You invariably start using
the "nice" library features of the language like STL and Boost and other
total and utter crap, that may "help" you program, but causes:

 - infinite amounts of pain when they don't work (and anybody who tells me
   that STL and especially Boost are stable and portable is just so full
   of BS that it's not even funny)

 - inefficient abstracted programming models where two years down the road
   you notice that some abstraction wasn't very efficient, but now all
   your code depends on all the nice object models around it, and you
   cannot fix it without rewriting your app.

In other words, the only way to do good, efficient, and system-level and
portable C++ ends up to limit yourself to all the things that are
basically available in C. And limiting your project to C means that people
don't screw that up, and also means that you get a lot of programmers that
do actually understand low-level issues and don't screw things up with any
idiotic "object model" crap.

So I'm sorry, but for something like git, where efficiency was a primary
objective, the "advantages" of C++ is just a huge mistake. The fact that
we also piss off people who cannot see that is just a big additional
advantage.

If you want a VCS that is written in C++, go play with Monotone. Really.
They use a "real database". They use "nice object-oriented libraries".
They use "nice C++ abstractions". And quite frankly, as a result of all
these design decisions that sound so appealing to some CS people, the end
result is a horrible and unmaintainable mess.

But I'm sure you'd like it more than git.

Name: Anonymous 2009-01-21 4:09

>>1
Indent your code first if you want us to help you.
CORRECT SOURCE AND RESUBNIT

Name: Anonymous 2009-01-21 4:10

>>35
This is one of my top 5 kopipes.

Name: Trollbot9000 2009-07-01 9:46

Around with Ubuntu and have been spending  time b fisting?

Name: Anonymous 2010-12-24 17:33

Name: Anonymous 2013-08-31 22:30



                    .|
      _,,....  __ _          |  ご  温
    ,. '" ,.ィ二7___!_`r-、.       |  
  ., ' /7'´   `   `!-ゝ_    |  ざ  州
  i   !/  /  ハ i    `ヽ!.   .|  
  i  /! ./ /-/-! ハ__ i !.    |  い  蜜
  ノイ レイ /,.-=、 !/ レ'iハ ,ゝ   | 
  i   ノ iイ"     . ´`!イ´    |  ま  柑
 ノ   !ハYト、.  、__ , "ハ〉   ∠
.〈r、  /ゝ- 、!>.、 __,,.インi      !.  す  で
  !ヘレ'/   `ヽ7ヽ!ヽ.Y)ヽ〉     ヽ、____________
    ,!     〉:ム:::}><{
へ___/!ゝk'-‐ヘ':::!_ハ」i_!ヘ!、
「 /::::::::`ヽ.  ヽ、:イ-ヽ.. ヽ. ,.- 、___,.--、
kヽ/:::::::::::::::::>、.  ヽ、__.ヽ、_,.'--'、: : ヽ-:、)、
:::`>、_二ゝ、ニr-'ヽ、   r'二 ̄ ̄ ̄ ̄ ̄ ̄フ
::/:::::::::!Y  r‐─‐'‐`'ー--‐'´ ̄ ̄ ̄ ̄ ̄ ̄
/::::::::::::)(   \ 
::::::/::::::Y)   ',|ヽ二二二二二二二二二二二

Name: Anonymous 2013-09-01 0:02



      ,. -‐'"´ ̄`''ー-‐')         /
   ト、/  ,. '"´ ̄ ̄`(`' ソ、       ;
   ; '  //   /    ヽ Y 、\       |
  /   / '  /,{    ト ハ  「 `      ,ゝ
  {   l  { /イ∧   ハァr、!ハノ       (
  '、 ' ル {f斤ヽ\/ {リ !{ ヽ、. 。 o ○ ` 、.,_           __.ノ
   ノイ/  l{弋り    .   Y、,ハ           `、.,__ノ´ ̄ ̄
  '´7 人   、`     _  人イ
   {ヘ.  >,、,>、 _/レ'  ̄`ヽ、
  /  `ヽ r'ヘ、 \{「、ヽ、     ':,
  ;    /´-、 \_r ァ‐ヽrへ r‐r- 、 :
  {   .{    \  ゝ_ノ/)::'"´`ヽ} |
  、  :,      ヽ  __/ / )::::<()::ト i
   ヽ ヽ、    ∨ヽ-、/ }:::::::::_ノ} リ
     `'ーヘ   /\/ l/`il`て_,,.イ
        ;  ./   ゝ--イ{|    |
      / { ri'      /}{ 、   /
      ,:'  /ヽ、    , '__}{__」`T´
    .l rく   ヽ--'´ /ヽ ∨

Name: Anonymous 2013-09-01 1:33



   ,.へ         /ヽ.
   io   `'ヽ.、.,_  _,/ __O',
   |     __,,..二='" ̄_<´i___   -─ァ 、、  i___ノ   /
   i o  ,>''":::::::::::::::::::::::::::`ヽ.O/        /´i /`ヽ. /、  
  /  /::::/:;::::::;::::::i::::::;:::::::`ヽ!   ヽ、___,   し'!  ノ / (__,.ノ
 くo  イ:::/::::/__/_;:!ハ!、__!ヽ::::i:::',  
  \/i::::レ:::。-─   ─-。レハ!
   く !:::::「`!" ,. ----、 "!_|:::!| /i ) ) イ:┬┬┬  ‐r‐ l二l二l
    〉;::::!__!、 !_________! .ハ:::!//   ┼┼┼┼.   ┼ .|___|___|
   /:::::ヽ!:::|:>、,  _,,..イ!/-''´./    ┴┴┴┴  ┴  ‐┼‐  
   !:::::/';::レ,.く__/〈〉、_〉_,,..-''´     ノ ヽ ヽ ヽ.    ─┴─
   )/   Y '!、__::/ハ:::::|´ 
   (´ ( 、_ヽ,______フ:〉::! 
          |:::::::::::O:::!
         .|::::::Oγ´',
         l:::::::::::::!、_人
        .└r-r-r-r‐'´
         |_/ |_/  ) )

Name: Anonymous 2013-09-01 3:03



          r-r、           ,.-ァ、
          |:::|`\         // |:::|
         ノ::/ \,ヘ、.     /::/ \|:::|
        く:::〈 // 、,べ  ̄ ̄`7/ /〉  |/
         .>ヽ/、__   _ゝ-、//__Y  /」
  /\    //〉^ヽ、二_,.ト-'、___!、_____/:::|`ヽ.
    ̄    / /-'、 / __ i  i  __   ヾ..  ',
   [>  /`ヽ! ィ7´/ ´/_ハ. ハ   !_ ` ',  i   i
     r/ ノー'ソ| /アi´'ヽ|_/ Lア!゛'`!ヽ. ,ゝ  ',
    ノ`ヽ、__イ-、|_,ハ ! ト_,リ     ト__ソノレ、」、   i
    / `''ー--' ノ'|  ハ"´   ,    `"/ |ノ   |
  /      ./、 !ノ .ハ、   rァ‐‐┐ く/  !  i |
  i´    、_/、_!く_/_」/>.、 、___ノ,.イ'`ヽ./   ハ |
 ノ    -‐'  |  ̄`'yアr'<`二i´ヽト-r‐-'、  i /|
 ヽ._      /     !/ / /ム |  / |',  `ヽ!'/
   `''ァー-'、'.___  .// |/ /  |/ | |    |〈 ノヽ.
    /   /  `/Y     ,'o     Y  _,.イ 〈〉-‐'
 [>|]   ハ  i ,!     !_      ハ'"  ', ヽ、
   〉   | ヽ、 Y `'r - ''|o`   イi i     ヽ. |〉<]
 [>/|    ',  Y rイ|   |     | ハ.      '"`'ー- 、
  |´ヽ.   ヽ. .| /::[ト、_,.-、!へ.,__,.イ]ヽiヽ.      /7`ヽ_
 __,ゝ )    )'/:::::::::::::::::、!:::::::::::::::::::::__', iヽ.    | |7´`ヾ.
 L_/Y \  //>:::::::::::::ヽ、レ:::::::::::::::::くく Y |ノ`ヽ.  ヽト、)、 〉

Don't change these.
Name: Email:
Entire Thread Thread List