mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The Frankie Yankovic polka was good but I wish the vid had them actually doing the polka - it would have lifted it from common to exceptional (you ain't seen nothing til you watch a roomful of large people polkaing especially when they have been dancing their entire lives).

I know what you mean, I lived in Germany for about a year. Polka is all they swear by when it comes to real big parties (incl. the Oktoberfest, of course). Of course, it's different from Cleveland Polka (as Frank Yankovic), but it's the same basic beat. What I love of Yankovic's music is just that overwhelming joyfulness of it. In between the seriousness of deep complex melodies and then all those songs about breakups or other downers (not to mention the "look at how cool I am" songs), it's refreshing to listen to pure joyful up-lifting songs for once. That's what I like about Polka, it's real party music, i.e., not fist-pumping party music, but "being happy" party music. That's the "exceptional" part for me. This illustrates that better.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Ahh... we were wondering what happened. Dani noticed that you deleted your account today, she was wondering why. I'm sure she'll be able to revert it. But of course, no one knows why you (or someone accessing your account) managed to delete your account without your consent.

<M/> commented: weird right? +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The same is true for line 32. Both loops are infinite do-nothing loops. I'm not sure what you tried to do, I can't really understand what's going on.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Should authorities be able to shut down a web site just because some people find it objectionable?

I agree that content cannot be taken down just because some people judge it objectionable, even when "some people" is actually the vast majority of people. However, the law can deem some things to be objectionable, in an objective sense. Now, this is a territory that ought to be treaded carefully.

To me, one minimum requirement is consent of the people involved. If you have a video / picture, there is must be consent from all the people involved (recognizable). Consent can be tacit or explicit. This is the way it works everywhere and I think it makes sense. Tacit consent is automatically implied until otherwise expressed. Meaning, if you shoot a video of me, you can publish it until I tell you not to or to take it down because I don't consent to it. In the case of a video or picture of a murder, it's a problem because the victim is no longer there to object, so, I think that consent should either fall to the family and / or require explicit consent before publication.

This is a purely objective legal stance that does not require making a judgement on whether the content is "objectionable" or not. That's why I think it's the best way to judge this situation. And it leaves the "free-speech" can of worms out, as well as all the cultural relativism that stultuske brought …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I guess I'll just share a few of my own eclectic obsessions too:

Frankie Yankovic ("America's Polka King")
Manu Chao
Scandinavian Music Group (it's in Finnish)
Radio Radio (the language is Chiac, if you're wondering)
Gnarls Barkley
Carolina Chocolate Drops (Jig or Folk)

A few French-canadian stuff too (I have to root for my own people):
Loco Locass
Coeur de Pirate

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, you're right. Good catch. Here is the correct version:

string squeeze(string s, char c)
{
    for(std::size_t i = 0, j = 0; i < s.length(); ++j) 
    {
        s[j] = s[i];
        do {
            ++i;
        } while( (i < s.length()) && (s[i] == c) );
    }
    return s.substr(0, j);
}
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

why not a little [?] thing that you can click for a tooltip description

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This looks suspicious:

1.5 million new lines of COBOL code are written every day
5 billion lines of new COBOL code are developed every year

If I know math correctly, I would say that 1.5 million times 365 days is only about 550 million, i.e., about 10 times less than the quoted 5 billion. Either way, one of those statements is BS, maybe both.

And also, adding this statement:

An estimated 2 million people are currently working in COBOL

Are we to believe that COBOL programmers average less than 1 lines of code per day? I knew COBOL was verbose / tedious, but that's a bit crazy!

And I also don't know how easily you can compare COBOL lines of code with lines of code in other languages. Every example of COBOL that I have seen seem to suggest that it takes roughly 4 times more lines of code to write something in COBOL than you would need in a more modern mid-level language like C++ / Java / C#, and certainly far more than is needed in high-level languages like Python and the like.

And then, I'm always skeptical of statements like "COBOL applications manage the care of 60 million patients every day". These statements always seem to imply that the entire software stack for a particular domain is done in that language, which is obviously not true. Any large system involving multiple computers, their OSes, networks, database servers, communication systems, end-user applications, and …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Obviously, people who commit murder ought to be prosecuted, and if a site receives footage or pictures of a real murder, then the site owners must report the footage to the appropriate authorities, otherwise, they are being complicit in the act and/or are obstructing justice (depending on jurisdiction).

That said, if they have complied with the law in that sense (either reported the footage, or obtained it after the murderer was prosecuted), then I believe that they can publish the footage essentially to the same tune as any other video footage. However, this means that the footage is still subject to normal consent to publish rules, meaning that people who are the subject of the footage (including the victim) must consent to the publication. I believe that in the case of footage of a murder, the family of the victim has the right to demand that the footage be taken down or censored. This is not about the free-speech of the site's owners, but about having the consent of the victim or his/her family / next-of-kin.

The issue with that though is that this generally requires the victim / family to come forth and request the take-down. That's just how it works (same as for TV footage and everything else). And because these sites are "hidden" in the dark corners of the internet, I doubt many people ever get notified that such footage concerning them (or a loved one) even exists.

I would agree that we could have laws that …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I have a number of tutorials that are partially complete, as I've had trouble finding the time to complete them. But now, I've started to teach tutorials on C++ at my university, so, I must "produce" now. So, you'll probably see a few tutorials from me soon. ;)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You clearly have serious problems with your code. Don't blame the debugger. That's counter-productive. If the error only shows up when you turn on the debugger, it does not mean that the debugger is causing the error, it means that error goes silent (unnoticed) when the debugger is not running. And I can't recommend that you "push through the sigseg", that does not fix the problem, it only leaves it in your code and will lead to much more serious bugs later.

You need to post more of the code if you want help with this bug.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

they took out all of the political and social commentary that was in the book and turned it into a "Brad Pitt saves the world" action flick.

Yeah, that's pretty much what they did. But it is a pretty good "Brad Pitt saves the world" action flick.

Social and political commentary is always taken out of any big-budget movie. It's a matter of aiming for the masses, which means no "message" that is either too meaningful or too complicated, to avoid offending or confusing anyone. I guess that's a social commentary in itself: most people don't want to be bothered to think critically nor be bothered in their preconceived notions. Big budget movies either re-inforce accepted notions or are completely trivial in their messages. It's like the Hunger Games going from a commentary on class warfare to a movie about an extreme reality show (which is, of course, an infinitely simpler and far less interesting issue).

Back on topic, I just saw "Kiss Kiss Bang Bang" yesterday. It's a pretty cool / funny movie, but definitely hard to follow at times, which I don't think matters much in this case.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

First of all, it is far simpler than it looks.

The first thing I will point out is that if you need a local copy of the string, then you should take that string by value (instead of const-reference), it is preferrable in general to do so, and it also leads to simpler code.

Then, you have to understand that the "squeeze" operation will always reduce the size or leave it intact. In other words, the destination string is always less than or equal to in size as the source string. For these types of algorithms, you can use a standard compacting strategy which involves traversing the array (or string) with two indices (or iterators): one placed at the output position (destination) and one placed at the input position (source).

Finally, to "squeeze" characters, all you really need to do is skip the duplicates.

When understanding these three facts, you get this:

string squeeze(string s, char c)
{
    for(std::size_t i = 0, j = 0; i < s.length(); ++i, ++j) 
    {
        s[j] = s[i];
        while( (i < s.length()) && (s[i] == c) )
            ++i;
    }
    return s.substr(0, j);
}

And that's it!

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

but in these case i belive that i can't use the 'const':(

That's right, you can't use a constant because std::endl is actually a free-function which gets implicitely converted to a function pointer, and then, within the stream's << operator, it is called on the stream. Anyways, long story short, std::endl is not a constant variable, so, to rename it, the easiest is probably a #define. The other option would be to use a wrapper function:

std::ostream& NewLine(std::ostream& out) {
  return std::endl(out);
};

which will allow you to write things like:

std::cout << "Hello World!" << NewLine;

But, if you ask me, this is all just a waste of time, just use std::endl and forget about it. Renaming standard things is generally just a bad idea, every single C++ programmer in the world knows exactly what std::endl is, you don't need to find a "more obvious" name for it, it's already clear enough to everyone concerned.

what isn't right with that line?

That line seems correct, as far as compilation goes, the define should work for your purposes. The two problems with that line is (1) that it is useless, as I already explained, and (2) that it breaks the MACRO convention that they should always be entirely written in upper-case letters to make it clear to all that it is a MACRO and not something else. That's all that is wrong with it, beyond the fact that MACROs are not to …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Why would the movie industry do these region coding.

The region codings are there to isolate the markets. The point is that if you produce a DVD for the asian market, it will generally be sold much cheaper than in the north american or european markets. If there were no region codings, people could buy DVDs produced for the asian market and sell them in the western world. The industry that controls the production of the DVDs wouldn't be able to control their prices. This is because the cost of producing and distributing them is almost negligible (it's all profit), meaning that the cost of DVDs do not reflect production cost (or money given to the artists) but rather the amount people are willing to pay for them. They could probably sell them for 50 cents and still make a profit. So, they need to maintain isolated and highly inflated markets where people can pay more (N-A, EU, etc.).

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It is not because the debugger tells you that the error is at that line that it necessarily is exactly that line which causes the problem. What is the broader context of that line? Could it be within a member function of a class? Maybe the function is called on a null/invalid pointer to an object of that class. If that line is the first line within a function body, the error is probably during the initialization / entering of the function. Debuggers generally do a best approximation of which line is being executed when the failure occurs, it is not always right on that line, especially if there is a scope (function body or otherwise) that is either starting or ending near that line (which triggers constructors or destructors).

And no, that line cannot cause a segfault by itself.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Just use Boost.Asio (C++).

Or, just use the POSIX functions in C / C++. It's not hard to do some UDP communication, a few lines of code, no more, and it's very intuitive. See this tutorial.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I guess modern is relative, if you are used to using vi, vim or emacs for all your coding needs (as many many people do), then, in comparison, sublime-text looks like an ultra-futuristic spaceship (not Xenu's spaceship that "looks exactly like a DC-8").

I tend to prefer when applications stick to the appearance that is standard in the host system. If I want a dark theme, I can set a dark theme on the system, I don't like to have to set themes / color-schemes for each application individually. And also, I have key-combination shortcuts to switch between different themes (useful when light conditions vary). Anyways... enough ranting about that.

I've been using sublime-text for a little while now, on and off. I'm not convinced (yet). I guess I'm too conservative. And I tend to dislike tools that require me to learn all about them, it often feels like the tail wagging the dog, or doing years of training in Kung-Fu in order to break a cinder block, instead of just grabbing a jackhammer and moving on. I just want to write code, and have pleasant visual cues from the syntax highlighting, that's all. I like tools that learn about what I'm doing (what language, what code, etc.) and adapt to that, not tools that demand that I adapt to it, whenever possible. That's why I'll probably have trouble warming up to sublime-text. Although, I do understand its appeal.

And I'm also weirded out by their license structure. They seem …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I tend to go for the stringstream class instead, because it is more "C++-style" and it has more options in terms of formatted input. For a simple string-to-int mechanism, I would just do:

std::stringstream(MovieRecord->getMinutes()) >> totalMins;

Or, in two steps:

std::stringstream ss(MovieRecord->getMinutes());
ss >> totalMins;

This is also nice because any type that can be read from / written to a standard stream can now be converted to / from a string, via the string-stream.

For a simple conversion, the C version is definitely shorter, but I still tend to use the string-stream version regardless, just for uniformity with the cases where the string-stream is definitely better (more flexible / generic).

N.B.: When you use C standard functions, like atoi, in C++, you still need to qualify them with the std namespace, e.g., as std::atoi (or through a using statement). Many compilers provide the C functions in the global scope, but that is not a requirement, and so, for portability, remember that they are in the std namespace.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

And those appear in the same header file as your Array's declaration, right? You cannot separate the declaration and definition of templates.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

1 - why some C++ PRO don't advice me use these code?(making properties)

Properties, like they exist in Delphi and C#, are certainly nice and convenient, but not an essential part of any language. I mean, they don't enable any particularly interesting coding techniques or patterns, i.e., they just make the code that uses the property a bit nicer and more uniform. There are some encapsulation benefits to properties, but nothing ground-breaking either.

In C++, you can achieve a very basic implementation of properties, either mimicking Delphi-style properties (with a property class template) or C#-style properties (with nested classes), as seen here. But in all cases, the basic mechanism used to "look like a variable" is the combination of an assignment operator (for writing) and an implicit conversion operator (for reading). This mechanism does a decent job, and is used for many "value-wrappers", such as my "award-winning" lockable class template. But, the result is definitely not perfect, and there are definitely compromises to be made with regards to how good things will look at the places where the properties are used. And since the whole point of properties is to achieve a perfectly uniform syntax where you use them. Any compromise is unacceptable.

The bottom line is that if you can't achieve an implementation of properties that give you something more intuitive, clean and painless than a "standard" good old-fashion get/set pair (which everyone is used to and familiar with), then it's not an …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Where is your implementation of the constructor of Array, specifically the constructor that takes one argument? The compiler is telling you it cannot find it, neither can I from the code you showed. Your NumericArray constructor requires the definition of the Array constructor, which is missing, apparently.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As their name implies, they shift the bits to the left or right. In other words, the bits are moved to the left or right by the given amount of positions. If I take the number 13, I get this:

For left-shift:

13      ==    1101   ==  13
13 << 1 ==   11010   ==  26
13 << 2 ==  110100   ==  52
13 << 3 == 1101000   == 104

And for right-shift:

13      ==    1101   ==  13
13 >> 1 ==     110   ==   6
13 >> 2 ==      11   ==   3
13 >> 3 ==       1   ==   1
13 >> 4 ==       0   ==   0

I don't think there is a way to put it more clearly than that.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

is there a possibility to write such a common compiler?

Most compilers out there are written as a front-end and back-end duo. The front-end takes care of parsing the language, applying syntax rules and converting all the code into a simpler kind of code (usually something close to the C language). Then the back-end takes that intermediate code and does all the final optimizations and the assembly into machine code that targets a given architecture (CPU). Most compiler suites share the same back-end for all languages, and simply provide a different front-end for each language. This is the case for GCC (GNU Compiler Collection), ICC (Intel Compiler Collection), Clang / LLVM, etc... So, yes, it is possible to write such a "common compiler", in fact, it is the only viable solution in the long-run if you want to support multiple languages. But, of course, it makes no sense to have one front-end that can deal with all languages, you just have one separate front-end for each language, all using a common back-end.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It seems to me that Qt has pretty much "won" at this point. Occasionally, people will mention that wxWidget is a bit more light-weight or something like that, but for the most part, it seems that cross-platform GUI development is dominated by Qt now.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I use the VLC equalizer for movies. Using a "hill-shaped" equalizer profile works great to enhance the dialogs and dull out the background music. By "hill-shaped", I mean low gain on the low frequencies, low gain on the high frequencies, and maximum gain on middle frequencies, i.e., making the shape of a hill. I'm too young (still) to be hearing impaired (but it will come for sure, as it runs in the family), but that doesn't mean I enjoy the crazy high-volume background music and stuff in movies.

But I haven't really found a need for a system-wide equalizer. I know many exist in Linux, depending on the audio back-end drivers that your distro uses (ALSA, pulse, Phonon, gstreamer, etc.).

I think it would be more practical to have an equalizer for the browser. I wouldn't want the same settings for my music, my videos, and my browsing (i.e., youtube and stuff). Most music players (obviously) and most video players have a decent 10-band equalizer. And if anything else is playing sound on my system, it will be some video streaming in a browser. Anyone know of equalizers for browsers (chrome in particular)?

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I haven't used DVD-rippers in a while. But a few years back, before I temporarily moved to Europe, I had a bunch of DVDs, bought in Canada. I could have brought them all with me (as a disk stack), but even then, I could not watch them, since my only movie-watching-device would be my laptop, and DVD players (the hardware, I mean) must be locked to one geographical zone (North America, Europe, Asia,...) with a very limited number of reconfiguring allowed (I could only change the zone 5 times in total). This would mean that any DVD I bought or rented in Europe could not be played on a DVD player configured for North America, and vice versa. This is obviously a market protectionist policy by the movie industry, to avoid competition between world markets. Anyways, this meant the only way for me to enjoy the products that I had legally procured for myself was to "rip" them to remove the encryption and any other DMCA crap. If some Hollywood law firm wants to argue that this is illegal (i.e., enjoy the things you paid money for), good luck to them, they'll need it (or, they'll need to buy politicians and judges, which is probably easier and much more common).

At that time, I just used the good old "DVD Shrink" software, works like a charm. I had to run it under "XP Compatibility", as it cannot run natively in Vista and later.

VLC can also rip DVDs.

For those …

LastMitch commented: Correct Answer +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The "Myths of Islam" that AD referred to is the title of the webpage he gave a link to. And if you read that page, you'll see that the "myths" that the title refers to are the myths about Islam, i.e., the things people believe about Islam that aren't true, or people's erroneous preconceptions about Islam. So, the word "myth" is perfectly appropriate, and shouldn't offend anyone, as it is not calling any of the beliefs of muslims as being mythical.

Please don't refer to them as myths, it kind of is offending. No one should refer to a faith as a "myth", it kind of is disrespectful...

I call all faiths myths. If you are offended by that, it's your problem. Free speech means that some people will express opinions and beliefs that offend or irritate you, it's your responsibility to learn to deal with that (it's part of being a grown-up), it's not their responsibility to work their speech around your particular sensibilities.

And if you want to argue things related to Islam, I would suggest you either start a new thread or revive the very interesting discussion we had a while back.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

For the compiler to be able to inline a function, it must see its definition (implementation). This means you cannot do the classic "declaration in header" / "definition in cpp file" paradigm. The definition must be in the header file. Marking the function as inline or __forceinline tells the compiler that this is what you will do, thus making the functions candidates for inlining.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

If you cannot use the C++11 swap functions, your best bet is probably to use the filebufs directly and construct vanilla istream / ostream objects from them. Something like this:

class my_ofstream : public std::ostream {
  private:
    std::string filename;
    std::filebuf* pfb;
  public:
    my_ofstream(const std::string& aFilename) :
      std::ostream( new std::filebuf(aFilename.c_str()) ),
      filename(aFilename),
      pfb(static_cast<std::filebuf*>(std::ostream::rdbuf())) { };

    ~my_ofstream() {
      delete pfb;
    };

    void swap(my_ofstream& rhs) {
      using std::swap;
      swap(filename, rhs.filename);
      swap(pfb, rhs.pfb);
      this->rdbuf(pfb);
      rhs.rdbuf(rhs.pfb);
    };

    const std::string& get_filename() const {
      return filename;
    };
};

Another option is just to keep track of the filebuf objects instead of file-streams, and create temporary i/ostreams just when you need them.

EDIT: Deceptikon's solution is much better!

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You cannot peek for more than one character. However, you can use the tellg and seekg functions to restore the original position after having done a multi-character reading. As so:

int peek_int(std::istream& in) {
  std::streampos orig_pos = in.tellg();
  int result = 0;
  in >> result;
  in.seekg(orig_pos);
  return result;
};
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I'm afraid your question is too unclear. Please give an example of what you would like to achieve.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What you want is the size of an element of the array, which is not sizeof(typeid(arr)). You need to use sizeof(arr[0]). Don't worry about if arr[0] exists or not, because the sizeof operator does not actually evaluate the expression, only its type.

Warning: The method that you are using, i.e., sizeof(arr) / sizeof(arr[0]), will only work for a static array, not for a dynamically allocated array.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Classic intelligence failure

I guess that's a mild way to put it. Even if you presume there was no nefarious aspect to it, it is still grossly incompetent. Intelligence has two aspects: the information gathered and the level of confidence about it. Getting the information wrong is not a failure by itself, but if you estimate that you have a high level of confidence about that information, and the information turns out to be wrong, then you are grossly incompetent, and this is a monumental failure. The fact that the "intelligence" about WMDs in Irak was presented as being of high enough confidence to warrant a preemptive war points to either a monumentally incompetent staff throughout the intelligence-gathering agencies, or a nefarious few individuals who misrepresented the facts to promote their agenda. With all the evidence, I have trouble dismissing the latter hypothesis.

As to Syria, guess where Saddam shipped a lot of his stuff when things started heating up in 2002?

I highly doubt that. First, most evidence points to Saddam not really having any significant amount of WMDs since the end of the first Gulf war. Second, if you think that Syria and Irak are two countries that were likely to cooperate with each other around 2002, then you are grossly misinformed about the politics of the middle-east.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah, I've referred people to that article so many times. There are great points, and it gives a good dose of "realism".

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I thought * value is the number the pointer value points to

Yes, but in order for a pointer to point to something, you need to allocate some memory and set the pointer to point to that memory. Before you initialize a pointer, it just has some arbitrary value and thus, points to some random memory location, which is why you get a seg-fault when you try to read/write that memory (which is most likely not part of the memory dedicated to your program).

To allocate memory, you should do something like this:

value = new int;

after which the pointer value will point to one integer. After that point, you can write its value with a statement like *value = intVal;. So, each of your constructors need to make such an allocation with new before it proceeds to set the value.

For a more comprehensive tutorial on writing all those functions when holding a resource, like dynamically allocated memory, refer to here.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You should also remove the using namespace std; from your header files. It is not acceptable to have using statements in header files. This is a rule to which there are no exceptions, period. You need to use std:: for each standard library component you use in your headers.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

So any conclusion for this? Did you just say impossible?

Nobody's talking about it being "impossible", everything is possible. What deceptikon said is that it currently does not work that way (not in C++, and not in any other language that I know of), and that making this work would be really hard (not impossible).

But one thing that needs to be clarified is that what you propose is, in general, a really bad idea, and will lead to far worse performance. So, this kind of feature would mean lots of pain and for no gain (in fact, tremendous losses in performance and effeciency).

Here's why. Currently, if you have a simple C++ class Vector2D with two data members (x,y), each being of type double, then the memory layout is something like this:

****************
|  x   ||  y   |

where each * represents a byte (i.e., a double is 8 bytes). So, the total size of the class is 16 bytes. If you want to access the data member "x", you just look at the double value at the address of the object. If you want to access "y", you just look 8 bytes further in memory. This also means that if you have 100 objects of that class in an array, all the of data contained in all those objects are within a single chunk of 1600 bytes, which is easily loaded on cache memory and easily and efficiently traversed and operated on.

If you …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

They are both correct, although people would generally write them as O(n) in both cases, because the 2 in the answer to (b) is not meaningful.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Good to hear you started using LaTeX. Once you get used to it, you'll probably never go back to using MS Word / LibreOffice programs.

And obviously, Tex/LaTeX is not a legacy language, even though it's quite old (1978). At least for most scientific publications, it's the only viable option.

As for posting questions about it, I guess it would have to wherever you see fit within the current categories. It's a bit weird in this case because it's not really "software" development (i.e., it is "document" development) and even though it's similar in nature to html / web development, it's not for the internet. I guess the main thing is not to forget to give it tags like "TeX" and "LaTeX".

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

where they have all this awesome software and I always wonder what it is.

3D animation / modeling is usually done with a professional suite of 3D animation software, and often in combination with in-house software / add-on scripts. The most popular software, from my limited and somewhat out-dated knowledge, is Maya / 3D Studio Max. But if you want to try your hand at this, I would recommend going with the open-source Blender software, which many people use, even for "real" projects because it is very feature-rich and easy to extend with in-house features or scripts. Blender is probably as close as you can get to professional 3D modeling software without having to significantly lighten your wallet.

You can also take a look at the wiki list of 3D modeling software. But you should understand that this is a very broad category, ranging in features (basic to professional) and application area (e.g., engineering drawings, computer games, or Pixar-style animations).

Also, understand that a lot of computer game companies have a significant amount of expertise in 3D graphics and also have a lot of custom rendering code and custom modeling formats that are intimately tied to their game development. This often means that in-house tools / add-ons can be very easy to make and effective to use, and probably not the kind of software they would consider selling or sharing with the world (and their competition!). Blender was originally just …

aVar++ commented: Very helpful reply! +4
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

anyone, this is from second year of IT, anyone passed that?

Seriously? What did you do the first year? Make macaroni art?

From the example:

if (x == 0) then  // O(1) simple variable access
      for i = 1 to n do // O(n)
           a[i] = i; // O(1) simple variable access

You just multiply every nested thing, so, you get:

T(n) = O(1) * O(n) * O(1) = O(n)

That's it. Any constant factor disappears because they are unknown anyways, so, answers like O(2*n) are impossible, it would just be O(n). And any terms that are smaller than the dominant term also disappears from the final answer (although sometimes keeped as intermediary result to show sub-complexities). For example, if you have this:

for i = 1 to n do  // O(n)
    a[i] = i;  // O(1)
    for j = 1 to n do  // O(n)
        b[j] += a[i];  // O(1)

Then, you get this:

T(n) = O(n) * (O(1) + O(n) * O(1))
     = O(n + n^2)
     = O(n^2)

because a quadratic term (O(n^2)) grows much bigger than a linear term (O(n)), and thus, "swallows" it when n is large.

Overall, this kind of stuff is very simple. For every loop, you just figure out how many times (on average) the loop will have to execute (e.g., in terms of the number of elements in an array, or some other quantity like that). And, for whatever is just a …

NathanOliver commented: Give them a link and I swear they just think you made the text blue. +11
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

multiply by 2 to the power of 15?

2^15 == 32768, I thought that was obvious.

All I did in that code was replace a line of code by an abstract function call, it was just to make you think about it at an abstract level, instead of just focusing on the details. You look at the initial piece of code and see a "division by the maximum value", and then, you wonder how to do the same when the type is double instead of short. What I want you to see in that piece of code is a "normalization to a range of [0,1]", and then, ask yourself what would be a meaningful normalization for your problem domain. For the author of the code, in his problem domain, the meaningful normalization was a conversion between the range [-32768, 32768] to [-1.0, 1.0]. What is yours?

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The problem with using the maximum value of a double is that you will most certainly lose all meaningful value in your samples array. For example, if you do samples[i] / std::numeric_limits<double>::max(), then it won't really matter much what the value of samples[i] is, unless it is extremely close to the maximum value. What you'll get is just a number extremely close to zero, within the number of significant digits. So, I don't think that such a strategy would make any sense. You need to rely on a meaningful upper-bound to your sample values.

When I see this code ABS(samples[i] / 32768);, to me, this looks like just a normal ADC (Analog-Digital Conversion) sample conversion to a floating point value normalized to the 0-1 range. This is because ADC units take an analog signal and convert it to a digital signal of a certain number of bits N, and thus, to an integer value within a range [0, 2^N]. To map that integer value back to the range of the analog signal (0 to 5 Volts, or just 0 to 1 in normalized units), you have to perform a very simple conversion, like samples[i] / 32768.

So, you have to see that function as doing this:

public void StaticCompress(short[] samples, float param)
{
  for(int i = 0; i < samples.Length; i++)
  {
    int sign = get_sign_of(samples[i]);
    float norm = normalize_abs_value( samples[i] );
    norm = 1.0 - POW(1.0 - norm, param);
    samples[i] = denormalize_value( norm * sign );
  }
} …
DavidB commented: Thanks for the input Mike. Your posts are always thorough, going above and beyond simply answering the question +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

The post quality score is definitely the best indicator for how worthy and awesome a member is. Shamelessly coming from another 97% scorer ;) (I'm sure JorgeM agrees with me!)

... says the person who has a 97% post quality score ;)

... says the person who has a puny 90% score ;)

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

A heap corruption problem is almost always caused by calling delete on a pointer that does not point to memory that was allocated with new. And yes, the strcpy function does not allocate memory, it only copies data from one location to another, it is your job to allocate the memory and make sure there is enough of it to perform the entire copy. The function that actually does both an allocation and a copy is called strdup (for "string duplicate"), but be aware that this function uses malloc for the allocation, and thus the memory must be freed with free (and also, strdup is not a standard function, it is a POSIX-standard function and is available on most platforms, including Windows).

Another thing to be careful about is that C functions like strcpy are in the std namespace, like all other standard C++ library entities. Some platforms, including MSVC, have them also in the global scope, but for maximum portability you should get into the habit of always writing either std::strcpy or with a using statement (like using std::strcpy; or using namespace std; at the start of the function's body).

i was thinking of switching to std::string to get loose from all this char* crap and reimplement the class, but how would it be possible to use char* for this?, i am curious

This is a bit of a problematic question, because you are shutting down the answer as part of the question. The reality is, in …

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You must be very tired indeed. ;)

When you construct the object "w" of class Something, it will contain a data vector with a size of 100. When you construct a second object "f" of class Parser, it will contain a data vector with a size of 0, because that's the size of an empty vector. The constructor of the class Parser does not initialize the size of the data vector within the object under construction to anything different than the 0 that it starts out with.

You almost seem to be confused about the difference between an object and a class. Each separate object contains its own set of data members (as declared in the class declaration). These data members are not shared between different objects, regardless of inheritance relationship, or even if they are of the same class. The data members that are tied to a class (instead of an object) are called "static data members", and must be declared with the static qualifier.

kal_crazy commented: very good explanation :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I've heard the phrase "with its new colors, Apple is redefining what an iPhone can be".... that smells of desparation and of extremely complacent "critics". I mean, Apple is, of course, legendary for over-hyping minor things as being revolutionary breakthroughs and paradigm shifts, but this takes it to a whole new level. Marketing is, of course, Apple's biggest strength (only strength?) and will go done in history as a company that truly revolutionized marketing strategies, but I think they have lost too much momentum and are starting to stretch things very thin.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Probably not the best implementation, but, hey! If anyone has any more, feel free to post :)

Definitely not, especially considering that it has a blatant memory leak.

Overall, I have a really hard time understanding what you actually want to accomplish. Even the title is confusing "CRTP without template arguments", in other words, "Curiously Recurring Template Pattern without templates", normal people would just call this "inheritance".

If what you want to do is somehow return a reference to an instance of Parser class via the Signal::Parse() function, and then copy that into a Signal object, then all you are doing is slicing an object. It doesn't "feel" right, to say the least.

I've read your posts over and over and I really can't understand what you want to the behavior to be. It is hard to understand behavior when all the functions are empty and thus, whatever happens, the effect is naught. Please provide a more concrete example, with data and observable behavior.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You can always count on good'ol jwenting to come out of the woodworks and intervene in any rational discussion, and take it all the way to crazy town.

IMO there's no such thing as "unacceptably rich". The whole idea that people should be kept poor

There is a middle ground between "unacceptably rich" and poor, you know? For example, you could double the income of nearly half of americans if you seized the income of the 400 richest individuals and redistributed it. This would literally eliminate poverty in the US. It's not about keeping anyone poor, in fact, quite literally the opposite.

Potential investors are taxed to the point they have no money to invest

1) You are probably taxed at a much higher percentage than any potential investor.
2) Investors are only taxed on captital gains or interests (and at a very low rate), meaning there is no adverse tax-consequence from investing the principal. And the alternative (not investing) is much worse, even as far as taxation goes.
3) "Never did anyone mention taxes as a reason to forgo an investment opportunity that I offered," -- Warren Buffett, while dismissing this argument that he qualifies as a crazy fantasy.

The Gold standard for currency worked well, until it was abandoned by countries needing a quick cash infusion for their governments that wanted to go on a spending spree for which their gold supplies lacked the backing volume.

Not at all. The …