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

There are a few options. Because a map iterator is only a bidirectional iterator (as opposed to a random-access iterator), you cannot simply write it + 4 to advance the iterator by four as you can with a random-access iterator.

I guess the first option is to use std::advance to get the iterator range that you want. As so:

std::map<int, Class>::iterator it = list.begin();
std::advance(it, 2);     // move to index 2
std::map<int, Class>::iterator it_end = it;
std::advance(it_end, 2); // move to index 4
for(; it != it_end; ++it)
{
    cout << it->first << "    " << it->second.GetPrice() << endl;
}

One of the problems with the above is that you are kind of doing the traversal (std::advance) before doing the traversal (for-loop), which is inefficient.

Another solution is to simply keep a separate count of the index. As so:

std::size_t index = 2;
std::map<int, Class>::iterator it = list.begin();
std::advance(it, index);     // move to index 2
for(; (it != list.end()) && (index < 4) ; ++it, ++index)  // inc. index, stop at index 4
{
    cout << it->first << "    " << it->second.GetPrice() << endl;
}

I think that this solution is better in general, and doesn't cost much at all.

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

You are missing the curly braces in this for loop:

    for(int j=0; j<=years; j++)
    cout<<"Enter runs scored by player"<<":"<<i+1<<": ";
    cin>>record[i][j];

You'll see it better if you space it out and indent properly:

    for(int j = 0; j <= years; j++)
        cout << "Enter runs scored by player" << ":" << i+1 << ": ";

    cin >> record[i][j];

As you see, the cin >> record[i][j]; is outside the scope of the for-loop. The error message is telling you that the variable j is undefined at that point. The reason the error message is weird is because it use to be (before the ISO standard) that the variable declared in the for-loop would exist in the scope enclosing the for-loop (e.g., holding the value it had at the last iteration), this rule has changed and is no longer allowed.

To fix the error, you need this:

    for(int j = 0; j <= years; j++) {
        cout << "Enter runs scored by player" << ":" << i+1 << ": ";
        cin >> record[i][j];
    };
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is also another nice (well-sourced) summary of the facts.

Here are a few key ones:

"Individuals in possession of a gun at the time of an assault are 4.46 times more likely to be shot in the assault than persons not in possession (Branas et al, 2009)."

"In another study, regardless of storage practice, type of gun, or number of firearms in the home, having a gun in the home was associated with an increased risk of firearm homicide and suicide in the home (Dahlberg, Ikeda and Kresnow, 2004)."

"For every time a gun in the home was used in a self-defense or legally justifiable shooting, there were four unintentional shootings, seven criminal assaults or homicides, and 11 attempted or completed suicides (Kellermann et al, 1998)."

"Another study showed that two-thirds of accidental firearms injuries occured in the home, and one-third involved children under 15. 45% were self-inflicted, and 16% occurred when children were playing with guns. (Morrow and Hudson, 1986)"

"Firearm suicide rates are strongly impacted by the rate of gun ownership. (Kaplan and Geling, 1998)"

"There is a positive correlation between homicide rates and availability of guns in developed nations. (Hemenway and Miller, 2000)"

"The cumulative lifetime cost in 1985 for gunshot wounds was estimated to be $911 million, with $13.4 billion in lost productivity. (Mock et al, 1994)"

"In the U.S. for 2010, there were 31,513 deaths from firearms, distributed as follows by mode of death: Suicide 19,308; Homicide 11,015; Accident 600." (remember that …

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

Sources?

I already quoted the source, here it is again:

L. M. Hepburn and D. Hemenway, "Firearm Availability and Homicide: A Review of the Literature", International Journal of Aggression and Violent Behavior, 9(4), 2004.

You can follow the references in that paper to get more sources, and read to your heart's content.

You honestly think if everyone had a gun on them at all times crime will increase?

I don't have to "think" so, it's a fact, as established by the comprehensive study I quoted.

So if a person has a knife on him instead of a gun and they are panicked just because they have a knife because of a gun they won't do anything?

Let me elaborate, which I didn't think was necessary considering how obvious this is to understand.

Case 1: Accident:
James accidently stabs his friend John, while mishandling a knife, which is a rare thing to happen (stab by accident). He most likely inflicts a minor wound to John, immediately feels terrible about the accident, drops the knife, and helps John to get some medical attention. The chances that John survives are extremely high.

James accidently shoots his friend John, while mishandling a gun, which is still somewhat rare but significant. He most likely inflicts a serious wound to John, immediately feels terrible about the acccident, drops the gun, and helps John to get some medical attention. The chances that John survives are good but not great.

Case …

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

This all depends on how you want to install it.

One option is to use a virtual machine, like VirtualBox. This will create one big file (that you place wherever you like) that is a kind of disk image. Basically, with this option, you can install Ubuntu (or any other OS) within the virtual machine and run it like a windows program. This is not ideal from a "native" experience point of view, and won't be as fast, but it is a good option to try at first and doesn't require committing a partition and setting up a dual-boot system.

The other main option is to install Ubuntu on a separate partition and setup a dual-boot system. In this case, it's a bit more tricky and you have to be a bit more careful. The partition on which you choose the install Ubuntu will be reformatted (all data erased). Usually, you can create a new partition instead of wiping out an existing one. Under Windows' partition manager, you can shrink and move your current partitions (which will not erase the data) to create some free space (I would say 20Gb minimum, around 100Gb is plenty enough). When you boot from the LiveCD/LiveUSB to do the installation of Ubuntu, you will have to select that free space as the place to install it to, and it will automatically create the required partitions and format them. Of course, before you fiddle around with the partitions (especially if you have to move a …

kvahanyan commented: Good answer, covered most of the topics he needs +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I don't see anything wrong with this code. My guess is that it is not a problem with either the printing or the iterators "resetting". It's most likely a problem with the creation of those vectors. In other words, what is being printed is exactly what is in those vectors. If you get the wrong things printed out, you probably put the wrong things into those vectors.

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

In the code above, it does return a pointer. This returns a pointer:

Rectangle* Rectangle::getInstance(int l, int w)
{
    static Rectangle firstInstance(l, w);
    return &firstInstance;
};

If you want to return a reference, you can use this:

Rectangle& Rectangle::getInstance(int l, int w)
{
    static Rectangle firstInstance(l, w);
    return firstInstance;
};

Either way, it's pretty much equivalent. A pointer is just a bit easier to deal with, but a reference is often preferred as a matter of good coding style.

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

you have it all wrong, no one wants to kill their neighbors we just want the right to protect ourselves and our family.

And from whom do you think you are going to "protect" yourself, if not your neighbors. That's what I meant.

Also it's more about having the god given right to protect yourself

Well, saying it's "god given" is pretty ungrateful towards the generations of people who fought (mostly with words) to give you those rights.

I'm referring to mostly outsiders, and extreme liberals in this country that believe taking weapons is the way to stop crime.

Empirical evidence is clear, reduce the gun possession means a reduction in crime. I won't discuss this further, this is just facts, and:
"Facts are stubborn things; and whatever may be our wishes, our inclinations, or the dictates of our passion, they cannot alter the state of facts and evidence." -- John Adams.

just not universal healthcare.

Yeah, because we all agree that some people just don't deserve to live. (sarcastic)
That's what "not universal" means, in case you didn't know.

When us "gun nuts" talk about guns it litterally means guns and it's also meaning the right to protect yourself which is essentially the peoples sentiment of security.

You misunderstood me. The "sentiment of security" does not mean that (at least, I didn't mean it that way at all). I have a sentiment of security when I can …

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

The Rectangle::getInstance(3, 3); is the syntax for calling a static member function of a class. Because a static member function is associated to the class only, not to objects of the class. In other words, regular member functions operate on one instance of the class (object), but static member functions do not, they are just defined as part of the class. Here are the different syntaxes:

MyClass my_object;  // this declares an object of class 'MyClass'.

my_object.callRegularMemberFunction();  // calls the function on the object 'my_object'.

MyClass::callStaticMemberFunction();  // calls a static function belonging to 'MyClass'.

my_object.callStaticMemberFunction();  // this is just for convenience, you can also call a static 
                                       // function on a object, but it is no different from the 
                                       // previous syntax with 'MyClass::'.

MyClass* my_object_ptr = new MyClass;  // declares a pointer to an object of class 'MyClass' and 
                                       // initializes it to point to a dynamically allocate object.

my_object_ptr->callRegularMemberFunction();  // calls the function on object pointed to by pointer.

my_object->callStaticMemberFunction();  // same as above, just an alternative syntax for calling 
                                        // the static function.

As for the Singleton implementation that you chose to use, it is a terrible one. There are many reasons why I recommended the Singleton implementation that I posted earlier. There are many alternatives that are really bad, the one you chose isn't the worse I've seen, but definitely not great. I highly recommend you go with the implementation I suggested instead.

As so:

Rectangle.h

#ifndef RECTANGLE_H_INCLUDED
#define RECTANGLE_H_INCLUDED

class Rectangle
{ …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Weapons are trivial for America to function, once they're gone it's OVER.

That's extremely sad. It's sad that you consider it a defining aspect of America; that people keep a piece of equipment in their house and be prepared to use it to kill their neighbors.

In some countries (..cough.. Canada ..cough..), people consider it a defining aspect of their country; that people would never wish harm on their fellow countrymen and have the confidence that their military could never even stomach the idea of turning their weapons onto their fellow countrymen.

In my perspective, when the people lose that sentiment, THAT is when it's "OVER".

My favorite quote: [...] "The people will not understand the importance of the Second Amendment until it is too late" - Thomas Jefferson

You might consider making this your new favorite quote:
"An educated, healthy and confident nation is harder to govern." -- Tony Benn

You seem so passionate about the issue of your guns being "jeopardized" (I am not sure what exactly you are referring to... the recent extremely weak and short-lived attempt at closing the gun-show loophole?). You might want to direct some of that passion towards other threats that are much more real and well underway for decades. I'm referring to the threats to the education, mental and physical health, and confidence of the American people. In the last decades, the education system has become massively underfunded, and undermined by pretenses that "teaching facts and critical …

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

This is called a Singleton class.

The most straight-forward way to implement it in C++ is as follows:

// in the header file:

class MySingleton {
  private:
    // private constructor:
    MySingleton() { };

    // private copy-constructor (left undefined):
    MySingleton(const MySingleton&);
    // private copy-assignment operator (left undefined):
    MySingleton& operator=(const MySingleton&);

  public:

    // public static function returning a reference to the singleton class:
    static MySingleton& getInstance();

};

// in the cpp file:

MySingleton& MySingleton::getInstance() {
  static MySingleton instance;   // a static local variable is initialized on first call to the 
                                 // function only, afterwards, it is always the same variable
                                 // for every subsequent calls to the function.
  return instance;
};

You can, of course, do the same but return a pointer, whichever you prefer.

With the above scheme, the user of the class simply has to use the getInstance() static member function to obtain the unique instance of the class. The instance will be unique within a single program. Because the copy-constructor and copy-assignment operators are private and undefined, it is impossible for a user to copy the instance either (called the Noncopyable idiom).

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

You must also keep in mind that in any half-decent implementation, the need for reallocations of the memory is an amortized constant cost, which is the case, of course, for all standard containers that rely on contiguous storage. So, any benefit you might get from the occasional in-place reallocation is marginal at best. In my experience, the cost of reallocations (create new memory and copy the old one into it) is almost negligible, and shows up only as low-performance spikes at geometrically increasing intervals.

You gain significant performance from using realloc only in situations where you are constantly increasing or decreasing the size of the array by small increments (e.g., like with the priority queue used in an A* algorithm). However, such an implementation is very very naive, the proper way to do it is with either a classic dynamic array (like std::vector) with amortized constant reallocation costs, or other more specialized containers like std::deque (multiple small arrays) or unrolled linked lists.

If you have an implementation of the A* algorithm that performs an order of magnitude faster because of realloc, it means that either everything else (besides memory management work) is really crazy efficient, or the approach used for memory management is really really bad (like the naive approach mentioned in the previous paragraph). I suspect the latter.

About realloc, I could conceive of some cases where you could achieve some marginal performance benefits from using it. But the reason why this "reallocate with the …

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

If you truly index by area then you have an array such that &array[area] is valid

I think your definition of "indexing" is bit off of the conventional definition of the term. For one, the OP states "a search index", which is very explicit. But even without that precision, the term "index" still refers to a method by which to look up elements of a collection / container. In an array, you can look up the elements by their position in memory (or offset from the first element of the array), and that's why we call that position value (usually an integer) the "index" of the array. But, in other contexts, the term "index" refers to whatever way you look up the elements. For instance, in containers like std::set or std::unordered_set, we say the elements are indexed by their value. In a container like std::map or std::unordered_map, we say the elements are indexed by their key values. There are also techniques for "multi-indexing".

So, to me, and to most programmers, when it is said "index by area", it means that the elements are looked up by their area values. It does not imply that every possible area value must be a valid integer index into a large array. And of course, that would be very wasteful of memory.

I don't like your reason for avoiding malloc;

Whether you like it or not, you have to accept it. malloc does not call any constructor, and …

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

Matlab / Octave:

disp('Hello World!');

Pascal / Free-Pascal / Object-Pascal (Delphi):

program HelloWorld;

begin
  writeln('Hello World');
end.

Fortran:

program hello
   print *, "Hello World!"
end program hello

Also, see this wiki listing.

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

Well, characters are just one byte integer numbers which are treated in a special way by streams (file, console, etc.) and displays (the console, text editors, etc.) so that they turn into specific symbols (letters) when displayed on the screen and treat certain special characters (new-line, carriage return, etc..). In C/C++, the char type is just that, an integer type (with values between -128 and 127) with some special semantics.

Now, in ASCII encoding (and most other encodings), the 0-9 digits have values of 48-57. This means that the character '0' is actually equal to the number 48. So, if the digit that is represented with the processTheseThree[0] character is the character '5', then it is equal to the integer value 53, and so, subtracting 48 from it will give you the integer value of 5.

The reason for subtracting the character '0' instead of the integer value 48 is because the platform is not required to used ASCII encoding (and often doesn't, it's usually a slight variation of ASCII). So, you can't be sure that '0' is actually 48, but you can be pretty sure that numerical digits and lower-case and upper-case letters of the basic alphabet will be all placed sequentially in the encoding table. In other words, you can rely on the fact that the character '5' will always have an integer value that is 5 increments after the integer value of '0', i.e., 5 == '5' - '0' is always true (not strictly required to be …

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

The trick to turn a single numeric character (digit) into an integer value is to simply subtract the value of the character '0' because it is almost certain (in all reasonable character sets) that digit characters have values that are sequential (e.g., in the ASCII table, the characters 0, 1, 2, 3... follow each other directly). And "char" is already an integral type, so, no explicit conversion needed. Try this:

        int D1 = processTheseThree[0] - '0';
        int D2 = processTheseThree[1] - '0';
        int D3 = processTheseThree[2] - '0';
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Yeah! I guess they only shoot in the summer (to get the show out in fall or winter).

I would love to see CSI:Iqaluit!
"Ok guys, let's investigate this crime scene. Grab your snow shovels!"
"What did the guys at the lab find when examining the body? - That it's still frozen solid."

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

The type char arrayOnes[10]; is an array of 10 characters. In your initializer, you are defining an array of strings (which are themselves arrays of characters). This would be the correct version:

const char* arrayOnes[10] = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};

The above defines an array of pointers to const-characters. A pointer to a const-character is the type of string literals like "one".

Of course, in more modern C++, we don't really use those kinds of C-style arrays anymore. In C++11, you would do this:

std::vector< std::string > arrayOnes = {"", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I guess you watch a lot of cops-and-robber shows. I'm surprised you missed this one:

However much I enjoy spectacular car chases in movies / shows, I absolutely hate how incredibly reckless they are. Some perp robs a bank, steals a car or escapes a drug bust in a car, and then the cops decide to call in every cop in the county to start a massive, super-reckless, high-speed car chase around the city and highways, putting every driver (including themselves) and pedestrian on the road in mortal danger and causing mayhem in the city. Yeah, right?!? A while back a cop near here chased a perp on the highway, reaching about 180 km/h (100mph) before giving up, she got fired the next day for reckless endangerment of the public. It simply makes no sense whatsoever to endanger the people like that just to catch one bad guy, regardless of how bad he is. The worst is that these movie car chases tend to give terrible ideas to some cops and from time to time you see a cops who thought he was actually supposed to do this in real life... what nincompoops!

I hate the "ticking bomb" scenarios:

For one, why are all these "terrorists" so optimistic that they plan for an exact time for their bomb to go off (as if nothing could ever twart / accelerate / cancel their plans), and don't think to build in a mechanism to remotely trigger or disarm the bomb at the …

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

You just forgot the * next to the type Object in your for-loop. It should be:

for( std::map<string, Object* >::iterator itr=_c.begin(); itr < _c.end(); itr++)
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

In RPM-based systems (Fedora, Red Hat, etc.), you generally use the yum command:

$ sudo yum install package_name

(where package_name is the name of whatever package you want to install, not the file name, just the name)

In Debian-based systems (Ubuntu, Debian, etc.), you generally use the apt-get command:

$ sudo apt-get install package_name

If you happened to have downloaded the package file manually, then you can install them directly.

In RPM systems:

$ sudo rpm --install package_file_name.rpm

In Debian systems:

$ sudo dpkg -i package_file_name.deb

On most Linux distributions, however, if you simply double-click on the rpm or deb file from the folder navigator (Dolphin, Nautilus, etc.., the "Windows Explorer" thing), it should auto-launch an installer window.

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

Just to add to that, two things I forgot to mention.

If you need to have "parameters" to dictate how you do the FFT (or whatever else), you can simply have a class with a template member funtion:

class FFT {
  private:

    /* some configuration parameters as data members */

  public:

    FFT( /* some params */ );

    template <typename InputIter, typename OutputIter>
    OutputIter transform_range(InputIter first, InputIter last, OutputIter out) const {
      /* do the FFT, using the params */
      return out;
    };

};

Also, if you still want to have a class that contains the result of the FFT, like you have in the original post, then you can simply use the generic function template that computes the FFT as the implementation of the FFT that your class uses. This means you get a "simple" but not-so-generic class for people to use and a zero-overhead generic function under-the-hood. In any given situation, you can use whichever is more appropriate: the generic function template for the more "special" situations; and, the wrapper class for usual (or less performance-critical) situations. I use this kind of pattern all the time, it is very convenient.

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

Do you really need a class?

Computing the FFT seems more appropriate as a kind of function than a kind of class. And you can make the choice of input / output containers external to that function by using the established C++ practice of using generic iterators. For example, you can model your function after the std::transform or std::copy functions. Simply do this:

template <typename InputIter, typename OutputIter>
OutputIter compute_fft(InputIter first, InputIter last, OutputIter dest) {
  // do the fft transformation here.
  // store individual results in "dest", e.g., *(dest++) = <next_value>;
  return dest;
};

int main() {

  int arr[] = {1, 2, 3, 4, 5, ......., 10};
  vector<int> result;
  compute_fft(arr, arr + sizeof(arr) / sizeof(int), back_inserter(result));

  vector<int> values = {1, 2, 3, 4, 5, ......., 10};
  vector<int> result_values( values.size() );
  compute_fft(values.begin(), values.end(), result_values.begin());

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

As simple as this:

#include <iostream>   // to print to console
#include <fstream>    // to read / write to a file
#include <string>     // to represent words (strings)

int main() {

  std::ofstream output_file;
  output_file.open("test.txt");       // open a file for outputting to it.

  std::string data = "Hello World!";  // create some "data" to be written

  output_file << data;                // write the data.

  output_file.close();                // close the file.

  std::ifstream input_file;
  input_file.open("test.txt");        // open the file for input.

  std::string data_from_file;         // create some place to put the data in.

  getline(input_file, data_from_file);// read one line from the file.

  input_file.close();                 // close the file.

  // finally, write the result on the console:
  std::cout << "Received this data from the file: " << data_from_file << std::endl; 

  return 0; // everything went well! Return value of 0.
};

You could easily split the reading and writing parts into two separate programs and you have what you asked for. For more info, read this tutorial.

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

The WebGL stuff makes sense to enable some rather simple browser-based 3D graphics, something that has been sorely missing for some time now, especially with the collapse of all the efforts for a 3D web standard of some kind (OpenInventor -> VRML -> X3D, and everything in-between and around that). Of course, it will probably remain fairly limited because it is (1) client-side and (2) hosted by a browser and a script interpreter. This severely limits the extent of the graphics that can be handled. But WebGL is going to be super useful for things from browser-based Google Earth kind of things to allowing better in-browser demos that use 3D graphics.

As for cloud-based 3D graphics, I don't think it makes any sense at all from an architectural point of view. It's all pain no gain. The buses involved in a computer architecture on the path between CPU -> GPU -> Screen are some of the fastest buses on a computer, typically in the order of 30-300 GB/s. And you're gonna replace that with... the internet, just so you can avoid the need for a piece of electronics the size of a pocket-calculator on the client-side. I think not. This thing is just a trendy sound-byte, it makes no sense in reality.

The only issue it seems is the bandwidth bottleneck.

Yeah, of course, bandwidth is always the issue, everywhere, in everything related to computers. If there were no bandwidth limitations on networks, on system buses, on memory …

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

There might be a stray character on the input stream. Try to use cin.ignore(); before the second input.

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

I think that this statement is wrong but only because big thinkers and doers since she put this book out have dismissed her way of thinking. At least that is the impression I have gotten about her.

Not so much dismissed her as much as distanced themselves from her. She is very antipathic to most people and not someone that any public figure wants to be associated with. Conservatives pretty much have to distance themselves from her because she was a strong atheist, and also, the fact that she rejected pretty much everything we typically call "christian values" doesn't help either in that crowd. Just look at how much back-pedaling Paul Ryan had to do in the last election when it was find out that he had, in his youth, been a fan of her work. She is basically political poison on all sides, but the most extreme and shameless fringe of US-libertarians.

In intellectual circles, she is basically poison too, for similar reasons, but also because of her blatant disconnection from reality. The main nail in the coffin of her arguments is that of evolution. Evolution is widely understood as having the effect of optimizing the traits of a population for better survival in their environment. And all social animals (and most animals are social to some extent) have developed strong empathy and altruistic behavior. Advocating for a lack of empathy and selfishness as the best way for society to work, means you have millions of years …

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

The library you are looking for is OpenCV (Open Computer Vision Library). It is used extensively in artificial intelligence / robotics applications for image processing tasks.

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

What great movies imo, so much so that I am getting the book.

Be warned, although her ideas are... well.. "interesting" (cough cough). Ayn Rand is well known as an insufferably boring, terrible writer (besides being known for being a psychopath idolator, of course). So, you might not enjoy the read as much as you expect to.

I like Ayn Rand's philosophy (so far)

Personally, any economic / sociologic philosophy that predates the main developments in Game Theory and in Bayesian Probability Theory of the 80s is like pre-Darwin biology: some interesting ideas here and there, but mostly stabs in the dark with very little empirical grounds.

her predictions have been coming true over the last (almost) 60 years.

Ever heard of self-fulfilling prophecies? Advocating shameless selfishness, rejection of empathy and legitimized greed is going to be very popular with those who have the power to influence policy and public perception. Like many others after her, rationalizers of the behaviors of the power-hungry tend to make for some very popular philosophers among the powerful. Who's surprised?

I'll leave you with this quote:
"I don't think there's any need to have essays advocating selfishness among human beings; I don't know what your impression has been, but some things require no further reinforcement." -- Christopher Hitchens, talking about Ayn Rand.

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

It makes no difference whatsoever when it comes to global symbols.

I tried the following source file:

#include "header.h"

#if 0

using company::module::ProjectConstants;
const int ProjectConstants::CONSTANT1 = 10;
const std::string ProjectConstants::CONSTANT2("Hello World");

#else

namespace company
{
  namespace module
  {
    const int ProjectConstants::CONSTANT1 = 10;
    const std::string ProjectConstants::CONSTANT2("Hello World");
  };
};

#endif

And I get the exact same list of symbols on the object file in both cases (#if 0 and #if 1).

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

I think they serve very different purposes.

I think that it is true that a lot of the wide-distribution applications for "light" work or for play are shifting towards web applications more and more. But that's because there are more and more people using the internet (duh!) and more companies and organization rolling out custom applications for some special purpose, and it is cheaper, faster and more convenient to release those on web platforms or languages or as iPhone / Android apps. And as a user, these are the kinds of applications you use everyday and all the time, i.e., they're in your face. There is no doubt that this market is big and growing.

But then again, most of these kinds of applications are pretty trivial. It is true that HTML / CSS / Javascript is really easy for making GUIs, easier to write and distribute than doing the equivalent in Java / C# / C++, but these languages are also limited to doing just that, set up a simple GUI with some trivial code (if any) running in the background. In other words, they don't do any heavy lifting. So saying that "desktop languages" will disappear is like saying that cargo ships should have disappeared after we invented airplanes, but the truth is, cargo ships are still the most effective means to ship large quantities of goods, regardless of how ubiquitous airplanes are today.

For instance, I work in the engineering and robotics field. Most of the work …

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

Mainly, stay away from those that are the most "strip down" distributions. You might hear that they are preferred by some programmers, but that's implying they are good programmers and experienced Linux users who like to temper with the system or set it up exactly as they want. Distributions to avoid are things like Arch Linux, Debian (pure Debian, not the derivatives), and anything based on Slackware, or any of the "server" versions (which usually means no GUI, no user-software, only server software tools). Most of these distributions are stripped to essentials or come with very little software such that you can build it up to your exact desires, and will inevitably require lots of familiarity with the terminal / shell (command-line interface).

Distributions that are friendly for the new user mainly include:

  • Ubuntu (and its friends) (desktop versions)
  • Fedora (and its spins) (desktop versions)
  • Linux Mint
  • OpenSUSE
  • CentOS, Scientific Linux, etc..

Just checkout the main distributions on distrowatch. One of the reasons to stick with one of the more popular distributions is to minimize the potential (and real) trouble when installing and configuring it (i.e., more popular distributions have been tested on more computer models and peripherals, and have a bigger community of people sorting out problems). There are usually some hick-ups when you first install Linux, so be careful and be prepared to have to do some troubleshooting to get everything running smoothly (there are usually a few peripherals and drivers that won't work right …

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

Any Linux distro is good for C++. The C / C++ languages are fundamental to Linux and GNU tools, not so much in Mac (C / Objective-C are the preferred language, and C++ is pretty terrible to use on Macs).

Qt is also a great choice for Linux (and all other OSes). Eclipse also works in Linux, as well as all the Qt development tools (Qt Creator, Qt Designer, Qt Assistant, qmake). I personally prefer KDevelop as my IDE.

I really like the Qt-based desktop environment called KDE. Any distro that uses KDE is a great choice in my opinion (Kubuntu, OpenSUSE, Fedora KDE-spin, etc.). KDE is a somewhat more conservative yet user-friendly and customizable desktop environment, and in many ways, it is very programmer-friendly. And of course, it is tightly integrated with Qt. In other words, it is a platform programmed in C++ with Qt, and it has lots of software to facilitate programming in C++ with Qt, i.e., made by C++/Qt programmers for C++/Qt programmers (among many other types of user).

But again, any other Linux distro is going to work great too for C++ programming, and overall it doesn't matter that much which you choose on that front since most Linux software is available in most Linux distributions. So, choose the distro you like best from a "normal" user perspective.

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

Yes, as I said, this is "fair use". You are allowed to grab some graphics and screenshots of the website to show "how it looks".

And yes also for embedded youtube videos. That's why youtube has the embedded video feature. As far as they are concerned the more visibility they get the better.

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

First, you need to use standard headers and only standard headers. The headers like iostream.h are pre-standard (before 1998), and should no longer be used, more the .h part (note: this is for standard headers only). The C-standard headers like math.h and stdlib.h must have the .h removed and a c must be added to the start. The conio.h header is an old and non-standard header dating back to the times of MS-DOS, few compilers still support it. So, the list of includes become:

#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>

Since the standard (1998), everything from the standard libraries are in the std namespace. So, things like cout are actually std::cout. To avoid having to put the std:: everywhere, you can just write this after the includes:

using namespace std;

Now, the code starts as follows:

int main() {

  char Continue;
  do
  {
    cout << "How many sales items do you have? : ";
    int hval;
    cin >> hval;

Notice that I have removed the list of variables that you were declaring at the start of the loop. Declaring variables en masse at the start of a function / loop is an archaic practice and is generally discouraged. Instead, declare variables close to where they are first used.

For instance, here I declare the isTotval just before I have the loop that computes the total of the sales items. Also, individual sales items are inputted in a local temporary variable ival, which …

adil.ghori commented: very very helpful.. Thank You Mike :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Of course you don't have to ask for permission to give your opinion on something, whether on a public website or anywhere else. That's an essential part of the "free" in "free speech". You can speak about anything to anyone, express any opinion you want, and you can offend people as much as you like too (pretty much anything short of a direct threat to someone or some people is allowed). But you also have to accept that someone might write a review of your website, saying it's garbage. That's the deal.

Unless you're in a country that doesn't respect the most basic human rights, there isn't much you can say or write that is illegal or worthy of any retribution.

Also, if writing website reviews, you are also allowed to grab graphics / screenshots from the website and put them up on yours as examples of what the site looks like. This is called "fair use". As long as you are not practically "stealing" their content to replicate their functionality on your site or something like that, you can grab bits of their graphics for your own fair use of it, with no need to ask permission.

As for Adsense, that is different since this is an association, and as per "free association", Google has the right to choose not to associate with you. Google certainly won't require seeing the content of your website before agreeing to have you use Adsense, but they reserve the right to pull out …

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

Just to add to that, the first step would probably be to write a software driver to basically make two hard-drives appear as one. You'd have a hard time doing this with internal hard drives because their drivers are pretty much baked into the firmware of the computer, but you might be able to do so by writing a driver for two USB external hard drives. That should give you a pretty good idea of the kind of logic you'll need to make this work. Basically, implement a software RAID driver first, and then you'll know what you're getting into if you want to move to hardware / firmware.

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

There isn't much point in delving into ICs unless you plan to mass produce. They are just electronic circuits made to be much smaller, far less energy-hungry and much cheaper to produce. If your interest is semi-conductor physics than that's one thing, but if your interest is electronics, do electronics, not integrated circuits. I.e., concentrate on the "circuit" part forget the "integrated" part, until you work for a big firm or research center, as rubberman pointed out.

If you want to do really low-level electronics stuff, you would normally build the circuit around a number of simple (and cheap) ICs for specific purposes (level converters, gate arrays, standard transistor bridge configurations, etc.). You would build the circuit as a custom PCB (Printed Circuit Board), which you can easily and cheaply make either through a company (you send them the plans and some money, and you get a shiny PCB in the mail a few weeks later) or by yourself (you can buy some home do-it-yourself chemical PCB etching kits).

If you are more interested in programming this kind of thing, then go with programmable logic instead. With a good micro-controller and a little bit of electronics work, you have what is needed to write the firmware for this. In fact, I'm not sure you could create a RAID module without a micro-controller of some kind (I don't know enough about RAID).

If I had to do this (i.e., most effective home-made solution), I would probably just replicate the USB connection …

ddanbe commented: Good explanation +14
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, the most complete source for information on the pre-processor is the section on it in the C++ standard document (you can download the draft for free, almost identical to the actual thing). The section only has 11 pages (which is extremely short of a chapter of the standard). The pre-processor is really simple, because it really should only be used for really simple things.

christinetom commented: Very extensive.. Thanks for the help. +1
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is by design. If you read the first thread on a forum, all the other threads are marked as read. I don't like this behavior either, but it is intentionally so (don't ask me why).

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

you shouldn't use the ${} evaluation for the variable in the for loop, at least, I never do. And the for loop will recognize the globbing too, so you shouldn't use the ls command. Try this:

for i in ~/Pictures/Screenshot\ from*.png;
    do
        mv ${i} /home/garrett/Pictures/ScreenShots/
    done
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Supporting void main() is acceptable in the sense that the compiler can just silently insert an implicit int return value of 0, and it's all the same.

Allowing zero-sized arrays implies that some objects can be a size of 0, which violates some core assumptions in the C++ memory model. I see it as much more brazen than most other extentions that generally just slightly bend a few corner-cases of the standard or allow for some older syntax traditions.

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

Many compilers have an "extension" to allow for zero-size arrays, I don't understand why, but they do. According to standard, this code should not compile. And those compilers that implement this zero-size array extension, end up producing a class with size of 0, as a quirk. In my opinion, this extension should not exist, but it does.

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

This is a case of return-value-optimization (or RVO). This is one of the few cases (with copy elision) where the compiler is allowed to change the behavior of the code (by eliminating calls to copy constructors and destructors) for optimization purposes. In other words, never depend on a specific number of copies being created as part of the critical behavior of your program.

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

@CimmerianX: Thanks for that, I have never used those things, but I expected it was this kind of crapware. And as you said, if you really want encryption, you should use a proper encryption system like truecrypt or a few others.

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

I think these drag-and-drop encryption things are usually implemented in the Windows driver that is loaded when you plug in the USB drive. Or, possibly, as part of the file-system used to format the USB drive. I think that once you re-format / wipe the USB, or disable that special driver, the encryption is gone and it's just a normal USB. So, it's probably no problem, but it might be, so better not buy that.

I don't see the point (unless you're a "noob") to buy an encrypted USB drive. You can easily format the drive with an encrypted file-system, and it will be far more portable and robust than the crapware that these USB drive snake-oil-salesmen put in it.

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

Will it be using markdown?

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

I haven't explored Chrome extensions all that much, but here are a few that I use and like:

Grammarly Lite - "Smart" spellchecker.
Session Buddy - This is an extension to manage sessions (a collection of open tabs). It is nice because if you have to close all browsers or shutdown the computer, you can just save all your current tabs as a "session" which you can reload later (when you come back).

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

The reason I could think of why some file formats start with size info is to calculate in some way how many "records" are in the file. But the OS file system provides that info also.

Generally, the file-size provided by the OS is not reliable enough (sometimes includes meta-data, padding, etc.). You can use the seekg( end ) / tellg() / seekg( beg ) method to find the exact size, but this is not guaranteed to be fast, it could result in reading the entire file content.

Another reason to have the size in the header is for integrity verification. If you get to the end of the file before you expect to, or if, for some other reason, there is a mismatch in the size, you must assume that the file is corrupt.

And finally, many file formats are actually the result of serialization code, and generally, when writing serialization code, you want to save some meta-data for each chunk of data (object) that you write, usually including a version number, a unique ID, and the size of the chunk of data. The reason for the size is so that the object can be ignored if it is not supported by the application that is reading the file, this is basic form of forward compatibility (making older software compatible with more recent versions of the file-format / software by ignoring unsupported features). Also, if you just want to ignore some objects, you just skip ahead. So, …

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

What makes you think that there is supposed to be a sequence of characters at the end of a file that indicate that the file has reached the end?

The EOF flag is artificial, it doesn't appear in the files. If you try to read / write to a file and the OS determines that you cannot because you have reached the end of it, you get the EOF flag as a result of the operator (either by setting the eofbit in the stream or returning EOF character from the char-read operation, or both).

The other place where you might use the EOF character is in an ASCII file that you want to artificially split into different files. But this only works for text files which will be read and interpreted. If you read a text file (non-binary), the characters that are read are interpreted, and if a EOF character is found, the stream will go into a failed mode, indicating that you have reached the end. If you expect more data to exist (i.e., another "file") then you can clear the error bits and try to read again. This can be useful, for instance, to pipe multiple files between programs in a BASH shell.

The character(s) is ignored in binary files, and it isn't a meaningful character that should appear for any other reason in a text (ASCII) file. When you do binary reading / writing, the operations are "unformatted", meaning the characters are not interpreted, and thus, any …