POV-Ray : Newsgroups : povray.off-topic : Games programmers : Re: Games programmers Server Time
10 Oct 2024 13:13:47 EDT (-0400)
  Re: Games programmers  
From: Orchid XP v8
Date: 11 Sep 2008 16:49:08
Message: <48c98444$1@news.povray.org>
Warp wrote:

> std::string someText(1000, ' ');
> someText += "Hello";
> someText.at(10) = 'A';
> 
> std::vector<int> anArray(1000);
> anArray.at(10) = 5;
> 
> std::vector<std::string> anArrayOfStrings(1000);
> anArrayOfStrings.at(10) = "Hello";
> 
> std::cout << someText << "\n" << anArrayOfString.at(10) << "\n";
> 
>   Lots of dynamically allocated data, no pointers anywhere.

So what's the lifetime of the data? The scope of the variable?

As I say, my major problem with C is that as soon as you need anything 
other than an int or a char, you start getting segfaults. (By the way... 
char, unsigned char, long char... WTF?)

>> Regarding rule 4... does this mean C++ at least manages to provide some 
>> standard containers *other* than arrays?
> 
>   Dynamically allocated vectors, strings, doubly-linked lists, binary trees
> (as sets, multisets, maps and multimaps) and double-ended queues. None of
> them requiring any pointers or 'new' to use. (The upcoming C++ standard
> will also include hashmaps as a new data container.)

Well that's something then.

>>> These rules should be broken only when you get very fluent
>>> with the language and know what you are doing.
> 
>> But you can 100% guarantee that any code you read that was written by 
>> somebody else will be full of such exceptions. ;-)
> 
>   Don't make the same mistakes as others.

But surely if I make whole *new* mistakes, nobody will have already 
worked out a solution for me? ;-)

(Only kidding...)

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.