|
![](/i/fill.gif) |
Warp escreveu:
> John VanSickle <evi### [at] kosher hotmail com> wrote:
>> Evidently not. In chatting with the interviewers that day, they all
>> confirmed that most bugs are stupid things like this.
>
> Sadly, the vast majority of people programming in C (or C++) professionally
> out there don't actually know the language enough to avoid such trivial ways
> to shoot yourself in the foot. It may be something that you and me can spot
> in a second, but I'm certain the average professional C programmer can't see
> it. It's no wonder programs are so buggy. A sad state of affairs.
>
> In C++ in particular this is another situation were the majority of C++
> programmers out there have no idea what's wrong:
>
> //-------------------------------------------------------------
> template<typename Value_t>
> class Array
> {
> Value_t* mData;
> std::size_t mSize;
>
> public:
> Array(std::size_t size):
> mData(new Value_t[size]),
> mSize(size)
> {}
>
> ~Array() { delete[] mData; }
>
> Value_t& operator[](std::size_t index)
> {
> assert(index < mSize);
> return mData[index];
> }
>
> const Value_t& operator[](std::size_t index) const
> {
> assert(index < mSize);
> return mData[index];
> }
> };
the C issues were self-evident, but this is not much easier than trying
to read some idiomatic haskell... :P
BTW, why
Array(std::size_t size):
mData(new Value_t[size]),
mSize(size)
{}
rather than
Array(std::size_t size)
{
mData=new Value_t[size];
mSize=size;
}
when you've got exactly 2 extra chars (:,) in the first case? Don't
tell me it's because some compile-time initialization that is not done
in the second case...
is also delete[] defined when you define those operator[] methods?
C++ is so alien...
--
a game sig: http://tinyurl.com/d3rxz9
Post a reply to this message
|
![](/i/fill.gif) |