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

@Stuugie: These kinds of scammers don't bombard you with malware. They smooth-talk you for a while and then ask for money with a pretext like buying a plane ticket to come and meet you or something like that.

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

Ubuntu is pretty good (personally I prefer Kubuntu, but it's a matter of taste).

One issue is that you might have trouble finding a place to buy a computer without a Windows pre-installation. Some small computer stores that assemble custom computers might be one option, but be careful about what you are buying from them, they tend to rip people off with sub-par parts that they want to liquidate. As for main-stream vendors, they have vendor-lock-in contracts with Microsoft that prevent them from selling computers without Windows pre-installed. I think Dell might still allows some business/professional grade computers to be bought without Windows (and with Ubuntu instead), but you have to call them up to find out.

Then, you have to consider hardware compatibility issues. Today, Ubuntu distributions are pretty good with hardware, most things will work out-of-the-box. However, there can be a few snags. You would be wise to search on the web for your considered models if they work well in Ubuntu, especially the graphics card. Here is a good start.

The biggest problem is gaming. Gaming in Ubuntu is pretty limited, mostly limited to indie games and open-source clones of classic games. Personally, that serves most of my purposes for gaming, but don't expect any new commercial games available on Linux (although, apparently, Steam is going to be ported to Linux, I don't know what games they'll be able to offer). You could always try to run games under Wine (Windows emulator for Linux), or …

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

Instead of if (*y == temp) to test if the element was found, you need to use this test:

if( y != a.end() )

Because if the element is not found, "y" will be equal to the end iterator, which means that it will be "not dereferencable".

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

Simply strip away the path from the names you get from GetModuleFilename or args[0]. As in:

#include <iostream>
#include <string>
#include <algorithm>

int main(int argc, char** argv) {

  std::string full_name = argv[0];

  std::cout << "Full name: " << full_name << std::endl;

  std::string exec_name(std::find(full_name.rbegin(),
                                  full_name.rend(),
                                  '\\').base(), 
                        full_name.end());

  std::cout << "Exec name: " << exec_name << std::endl;

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

Yes they do, scientists do that all the time. That's why we now know the Earth is round and that it revolves around the sun. I also know of one who tried to prove a strong correlation between the rising moon and pregnancy. Or other scientists who study the breeding habits of flys.

When I said "non-sensical" I didn't mean "irrelevant". You may find that some of the things that scientists study (like breeding habits of flies) are irrelevant, or at least, in your opinion. Judging the relevance of one or another thing is subjective, and also, the possible impact of a given topic of research can be hard to foresee. But that is not what I meant by "non-sensical" at all. Sure, scientists investigate irrelevant stuff all the time, depending one your assessment of what is relevant and what is not. But, what they don't do is investigate questions that don't make any sense (i.e., "non-sensical").

If you ask: "What are the inner-thoughts of a tree?", that makes no sense, at least, not until you can establish that trees have any kind of consciousness and a means to communicate their thoughts.

If you ask: "What color do rocks prefer?", that makes no sense, because rocks can't have preferences, or a means to perceive colors.

If you ask: "What was before the Big Bang?", that makes no sense, because, by definition, the start of the big bang is the start of the universe, and there cannot be anything …

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

brothers: if you people really beleive that the the whole universe, the space and time, the matter and energy, was created by itself out of nothing and call it a logical point of view, i wonder what kind of logic you have.

I never claimed the whole universe was created out of nothing. For one, I have no idea what "nothing" is supposed to be. Put that aside for now, the reason most people might say that something cannot be created from nothing is because that never ever occurs in people's normal life experience. But this also means we have never observed a God creating something from nothing either, so why would that belief be any less crazy.

In any case, the question of the origin of the universe (by that, of course, I mean the first nano-second) can only be the subject of speculation and hypotheses because it is currently impossible to observe and our currently best scientific models break down at that time. Claiming that you know anything about it is an extraordinary claim that would require extraordinary proof, and scientists will be all ears open if you present that evidence. Scientists are very open-minded, but they only accept things that have supporting evidence.

Currently, the scientific speculations about the origin of the universe include a number of different hypotheses. One that I particularly like is the fractal universe hypotheses, which is, in layman terms, kind of like saying that our universe resides in a kind …

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

Welcome!

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

Thanks for the nice poem! Woot Woot!

Being human is hard, I'm still learning...

One thing I noticed is many people are 'speaking in code'

I sometimes find code easier to understand than "human language". Might have something to do with being dyslexic.

I try to be nice to noobs, and I wouldn't be helping people out on these forums if I didn't care about teaching. But I also believe that using rigorous language is the foundation of a good understanding, so it sometimes becomes hard to balance layman explanations with technically accurate terms.

But, all in all, people here are not as "robotic" as you may think, in fact quite the opposite. The proof of that is the diversity of the people and their approaches, and perhaps their mood-swings as well. If you had poor experiences with some people here, then just remember that they are just humans. Overall, this is a very nice community that is very welcoming to "noobs". In fact, I would say it is one of Daniweb's strong suites.

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

Who is going to pay the bill then? Answer: taxpayers

You misunderstood the situation. Traditionally, up until now, there has been a public (from taxpayers) financing of electoral campaigns. What this means is that there were strict limits on the amounts that political parties could raise from individuals (and couldn't take any money from companies/corporations). So, most of the money for political campaigns would come from taxpayer dollars which are handed out to political parties based on their proportion of popular votes and seats in parlement as of the last election, and there was some progression in the amounts so that small parties have a running chance too. Basically, this puts all major parties (3 or 4 of them, usually) on a more or less level playing field, but most importantly, parties do not have to rely on powerful and rich friends in order to have a running chance, which is a big plus for fending off corruption of politicians. And, the total campaign expeditures are not high enough to make them any kind of significant part of the overall government budget. This is a minor taxpayer expenditure, that makes a huge difference. Now, the conservative government is phasing out this system because they know that they have powerful and rich friends and that their competing parties do not (or not as much), and so, it will give them the upper-hand in the next election, and after that, we will end up with a system like the US …

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

Not only are you writing beyond the size of the array (i.e., because at the last iteration, i == N and thus, i+1 == N+1, and thus, the loop-expression becomes u[N+1] = 3*u[N] + 4;, and the one iteration before that (i == N-1) is also writing beyond the bounds of the array), but you actually don't need to use an array at all. In order to compute the expression within the loop, all you need is the value computed from the previous iteration. So, you don't need to store the entire array of values from 0 to N-1. Try to rewrite your code without using an array.

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

And what exactly does a factorial or fibonacci calculation have to do with the problem you are asked to solve?

Can you try to solve the problem that you are asked to solve?

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

islam and logic is really a very good topic to discuss about, as i m a muslim and i truly beleive that islam is the only logical religion.

I beg to differ, "islam and logic" is a pretty bad topic for the simple reason that logic alone isn't very useful, certainly not sufficient to justify belief. I could make up any weird supernatural story that is entirely consistent and logical, but it still wouldn't be true. At the basis, to justify belief, you need evidence, then you can start with the logic arguments, but only when you have established that your founding assumptions are true via a solid amount of evidence.

one of the proof in this regard lies in the name of islam.

A name cannot be a proof of anything. I can invent a religion and call it anything I want, like "The-one-religion-that-is-true", and then claim that my religion's name is a proof that it is true!

This is generally a good test to evaluate "logic" arguments / "proofs". If you can imagine inventing a religion out of thin air, and that your "logic" argument could hold just as well for that invented religion, then it means that your argument is worthless.

first thing that all of you will beleive is that there is a some supernatural power,called God, who created this whole universe.

No. I don't believe that. And in any case, the fact that many people believe in a supernatural …

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

Is it your belief that the more handguns that are in circulation the safer everyone is?

Absolutely yes.

"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." - Kellerman, et al. 1998

In other words, empirical studies show, undeniably, that a gun is far more likely (22 times more likely, in that particular study) to be involved in an unfortunate accident, criminal act, or a suicide, than in an act of self-defense. Your comment is basically the same as compulsive gamblers who walk into a casino being convinced they will beat the house, even though all the odds are stacked against them. There are no rational arguments to defend the point of view that personal gun ownership improves safety overall. Facts are annoying, I know...

At the same time I'm in favor of ban on assult weapons because they have no other purpose than to kill people.

So... handguns are not assault weapons? I don't see many people shooting deer with Desert Eagles or Berettas. I guess, you'd say handguns are for self-defense, while assault rifles are for assault. Well, the M16 is common in Israel as a self-defense weapon that ordinary people carry around. I'm not saying that's a good idea either, I'm just saying the line is blurry. And if you start arguing that the primary purpose of …

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

These are the result of posts that got deleted by one of the moderators. Someone posts some spam or inappropriate post, it bumps up the thread, a lurking moderator reads it, deletes it, but then the thread remains bumped up. Unfortunately, this tends to happen to old threads too.

As a moderator, I can see the deleted posts, and that thread you linked to has three deleted spam posts at the end of it.

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

This is a dangerous question, things can easily escalate into a flame war.

It is very difficult to answer this question without knowing the specific kinds of differences you want to know about. There are countless technical and application differences between the two languages. You should probably start by reading both wiki entries, C++ and Java.

Here are some of the broad strokes (I'll try not to sound too much in favor of C++):

Main goals of the language:
C++: Performance and robustness.
Java: Safety and portability.

Syntax and style:
C++: Syntax is based off of C, with additional keywords for the plethora of additional features it has. Style varies, usually with the paradigm being used.
Java: Syntax is based off of C with most object-oriented syntax borrowed or heavily inspired from C++. Style is quite uniform, the Java-style is the de-facto standard style for "pure" object-oriented programming.

Typical running environment:
C++: Compiled to native machine code, runs as a native program on the target architecture (e.g., x86), must be recompiled for any different-enough platform (majorly different operating systems or architecture). Target platforms are anything from micro-controllers to super-computers and server farms.
Java: Compiled to bytecode (a kind of pseudo machine code), runs inside a virtual machine (Java Virtual Machine, or JVM), one Java "executable" can run on any platform (i.e., that is running the virtual machine). Target platforms are mostly consumer platforms (PCs, smart-phones, etc.) and servers (server-client applications).

Programming paradigm:
C++: Multi-paradigm language, the …

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

See how far you can edit that list of number.

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

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239

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

Did you include the header <algorithm>? Normally, this should be resolved by overloading. And you might also want to remove the using namespace std; statement. This remove function that you are getting is this one from cstdio. If you include the <algorithm> header, the overload resolution should be able to find the correct remove function.

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

GCC: "GNU Compiler Collection"

The collection includes:
gcc : C compiler
g++ : C++ compiler
gfortran : Fortran compiler
g77 : Old Fortran 77 compiler
gobjc : Objective-C compiler
gcj : Java compiler
gnat : Ada compiler
gccgo : Go compiler

And you're right, the gcc program will forward source code to other compilers based on the file-extension (but that behavior can be disabled through an option), making the gcc program a kind of one-stop-shop for compiling anything.

"Installing GCC" usually refers to installing all of the above (since, in any case, it is only the front-end that is different between compilers), and the bulk of the installation is the library suites, the back-end programs and all the utility tools (e.g., like the linker, which is the same for all).

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

I just installed the latest and greatest -- it's up to 4.7.8

I was talking about the GCC version, not the MinGW version. I doubt that MinGW has GCC version 4.7.8, since they would need to have a time-machine a go a couple of years into the future to get that version (if it ever will exist, since GCC versions usually end at 3-4 minor revisions). The current experimental branch is 4.8.0 for a built-from-source, bleeding-edge version of GCC.

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

The only compiler that currently supports "template aliases" (which is the name of this feature) is GCC version 4.7.0 and later (experimental). So, that's the compiler you need to install if you want that code to work. For Windows, MinGW has recently release a version with 4.7.0. As for Linux, you can look for up-stream repositories that carry bleeding-edge GCC versions, or you can build it from source (as I do).

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

You simply install MinGW to any directory (like the recommended directory C:\MinGW). Then, you go into Dev-C++, into the global options "Compiler Options". There, you should be able to set up the directory in which to find the gcc compiler, set that to C:\MinGW\bin (or the equivalent). There are also other directories to set up. Basically, watch for anything that references the old MinGW directories and switch those directories to the new installation (the sub-folder structure is the same for all MinGW versions). Verify that the "programs" names are correct (should be things like gcc.exe). And that's about it when it comes to changing the compiler to a new installation.

As for version 4.6, it allows some C++11, but not all. You can look at this table for a per-feature breakdown of the minimum version required. MinGW now supports version 4.7.0, that would probably be a wiser choice if you want to experiment with C++11.

Ancient Dragon commented: great info :) +14
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Hi,

There is a bug with the editor that I noticed and others noticed too. When you post a very long code segment (or maybe just a long post, period), at some point it seems to overflow the capacity of the editor and you can no longer scroll all the way to the end of the post. The scroller becomes weird and jumps around, but you can never get to actually see the latter end of the post in the editor. You can still edit the content after where the editor stops, and that content still turns up in the final post, but you can't see what you are writing (except through the live preview, which is of course not viable for that purpose).

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

All I did was read the error message that you got. See, it helps to pay attention to the error messages!

Lesson learned, I hope.

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

Read the error report:

... in explosionhandler::registerexplosion (this=0x0, ...

Obviously, the "this" pointer is NULL, which means the error is in the code from which this function was called. You must post that code if you want us to help you find the error.

As for the bug with posting long code segments, I have noticed that too, I will file a bug report about it.

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

The code box should appear above the text box immediately after you switch the type of article to "Code Snippet". If that doesn't happen for you, then it is either a problem on your side or a bug in the page. For me (Chrome, and Linux), it is all right.

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

I don't see anything confusing about it. When you write a code snippet there are clearly two sections when creating the post, a section for the text and one for the code. As for being able to also put code in the text section, well that can be useful for a separate piece of code (like the test harness) or for explaining the code with extracts from it.

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

One more thing, to clear the misunderstandings:
@ModernC++:

MBR can only boot Windows,

@capton:

I just don't like the interface MBR gives me.

MBR stands for Master Boot Record. This has nothing to do with Windows or any other operating system, it is nothing more than a reserved space at the beginning of any memory device (hard drive, USB stick, CD/DVD, etc.) where the BIOS will look to find code to boot the computer (i.e., the boot-loader). There are also VBRs, for Volume Boot Record, which is the same as MBRs but for individual partitions (a reserved space at the first physical address within a partition). Again, both have nothing to do with any particular OS. Also, when one says to "make a partition / hard-drive / CD / USB bootable", that means to install a bootloader (Grub or otherwise) on its MBR / VBR.

When Windows is installed on a computer, it will install the Windows Boot Manager, usually on the MBR (by default, especially when pre-installed on the computer). But the Windows Boot Manager can also be installed elsewhere (e.g., on the Volume Boot Record of its install partition). This is what you guys are calling the MBR, but it should be called either the Windows Boot Manager, or just "Windows bootloader". To edit the configuration of the Windows bootloader, you use a program like EasyBCD or the Windows system tool called bcdedit.exe.

there is a …

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

Well, if you configure the windows bootloader to have only the Linux (grub) option (i.e., by removing the Windows option), then it should boot to grub pretty much directly (the Windows bootloader will not appear at all if there is only one option). Another thing you can do is set the time-out to 1 second for the Windows bootloader, with default option being Linux (grub), this way you will only set the Window bootloader for a very short period of time before it goes to Grub. Both of these can be done easily with EasyBCD (free version).

The last option is to reinstall grub on the MBR, overwriting the Windows bootloader. That's not difficult to do either through the LiveCD menus or from within your installed Linux distro (once you've booted to it). Within Linux, you just enter the command $ grub-install /dev/sda (or whatever device name identifies your hard drive). Here is a complete guide on using and tweaking grub.

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

Ok, so the solution to all your little mismatch errors is that the template <> is not needed before the function definitions. Sorry about that, it slipped my mind.

You also had a lot of errors in addition to that. I went ahead and solved a few of them, at least, to get it to compile. However, your implementation of the char* specialization is very wrong and is leaking memory all over the place, you will probably need to revise it entirely, but my guess is that you just didn't get to that point yet, now you are, with this corrected code:

#ifndef SIMPLEVECTOR_H
#define SIMPLEVECTOR_H
#include <cstdlib>
#include <iostream>
#include <new>
#include <iostream>
#include <cstring>

template <typename Type>
class SimpleVector
{
    private:
    Type* aptr;
    int arraySize;
    void memError();
    void subError();

    public:
    SimpleVector(int s = 0);
    SimpleVector(const SimpleVector&);
    ~SimpleVector();
    int size() const
    {
        return arraySize;
    }
    Type getElementAt(int);
    void setSize(int);
    Type& operator[](int);
    void push_back(const Type&);
    void pop_back();

};


template <>
class SimpleVector<char*>
{
    private:
    char** aptr;
    int arraySize;
    void memError()
    {
        std::cout<<"ERROR CANNOT ALLOCATE ! ENDING THE PROGRAM! ";
        exit(EXIT_FAILURE);
    }
    void subError()
    {

        std::cout<<"INVALID SUBSCRIPT! ENDING PROGRAM";
        exit(EXIT_FAILURE);
    }

    public:
    SimpleVector(int s = 0);
    SimpleVector(const SimpleVector<char*>&);
    ~SimpleVector();
    int size() const
    {
        return arraySize;
    }
    char* getElementAt(int);
    void setSize(int);
    char* operator[](int);
    void push_back(const char*);
    void pop_back();


};


template <typename Type>
SimpleVector<Type>::SimpleVector(int s)
{
    arraySize = s;
    if(arraySize == 0)
    {
        aptr = NULL;
        return;
    }
    try
    {
        aptr = new Type[arraySize];
    }
    catch(std::bad_alloc)
    {
        memError();
    }


    for(int count = …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

MBR is an area at the very beginning of the hard drive. When you start the computer, the Bios (which is a little hardware program on the motherboard) looks for the hard drive (and other bootable devices) and if it finds a hard-drive, it starts running the code present in the MBR. That code is what is called a bootloader. It's a simple program that launches the operating system. Grub (or Grub2) is one such program. Windows uses its own bootloader as well.

When you install a Linux distro (that uses Grub), you have two choices. First, you can install Grub on the MBR, which overwrites the Windows bootloader. This will make booting to Linux the default but you can still boot to Windows via the last entries in the Grub menu. The second option is to install Grub somewhere else (usually the same partition as the "root" of the Linux distro), which leaves the Windows bootloader intact. At this point, you cannot boot into Linux because the Windows bootloader does not have an entry for that. To fix that issue, you use a program to add an entry to the Windows bootloader, either use BCDEdit or EasyBCD to do so, follow online instructions for that. Basically, after that is done, when your computer starts, the Windows bootloader will appear with the Linux option (in addition to Windows option), and if Linux is selected, it will jump into the Grub bootloader in your Linux partition, at which point, …

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

I don't know much about online degrees, but I am a robotics engineer, so I might weight in a bit here.

First, you have to watch out when looking up online degrees because there are a lot of fake colleges or university, for-profit colleges and so on. Also, potential employers will be wary of any fishy-sounding degree, I know I would be.

But, there are respectable universities that do offer legitimate online / part-time degrees that would be as good as any. If you make sure of the legitimacy and quality of the online degree you pursue, there shouldn't be too much prejudice related to that, but I may be wrong.

In any case, having a lot of work experience, even at a "lower" level (technical tasks, etc.), is very valuable. Especially in robotics, there are hardware issues all the time and having people around that are very comfortable diving into that and solving those issues quickly is a huge bonus. In robotics, the bulk of the work is software, software, software, but when hardware issues hit (and they do very often) it is so nice to have people who are just as comfortable with a soldering iron as they are with a keyboard. The point that I'm making is that I would hire a guy (or gal) with an online degree and lots of hands on experience over a guy (or gal) with an honours degree (and immaculate record) and only short internship experiences, without even blinking. So, keep …

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

First of all, templates cannot be split into a header and cpp file like normal classes or functions. Read this FAQ for an explanation. So, that might be the root of some of the errors.

As for the actual error you pointed out, I cannot tell you what's wrong if I don't have the code in question.

As for class versus typename in the template argument declaration, there is no difference whatsoever between the two. It is only a matter of preferrence. In my experience, it seems typename is more conventionally used than class. I personally prefer it too, just because the class keyword can be a bit misleading, as to think that the type in question has to be a user-defined class (e.g., class Foo { }; or something), when in reality it can stand for any type, and thus, the keyword typename sounds more clear to me.

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

To do the specialization, you must repeat the full declaration of the class for the special case, as so:

// general template:
template <typename T>
class my_vector {
  private:
    T* data;
    std::size_t data_size;
  public:
    //...
    void set_element(std::size_t i, const T& value);
};

// specialized template
template <>
class my_vector< char* > {
  private:
    char** data;
    std::size_t data_size;
  public:
    //...
    void set_element(std::size_t i, const char* value);
};

// implementations:

// ...

template <typename T>
void my_vector<T>::set_element(std::size_t i, const T& value) {
  data[i] = value;
};

// ... 

template <>
void my_vector<char*>::set_element(std::size_t i, const char* value) {
  std::size_t val_len = std::strlen(value);
  delete data[i];
  data[i] = new char[ val_len + 1 ];
  std::memcpy(data[i], value, val_len + 1);
};

If you want to only specialize a few functions and reuse the general functions for most other things, then you need to create a second class that implements only those "to-be-specialized" functions and then do a template specialization on that class instead. Or, you can do it as free functions, which you overload for the special cases, as so:

// general template only:
template <typename T>
class my_vector {
  private:
    T* data;
    std::size_t data_size;
  public:
    //...
    void set_element(std::size_t i, const T& value);
};

// set-element implementation function:
template <typename T>
void set_element_impl(T* data, std::size_t i, const T& value) {
  data[i] = value;
};

// set-element implementation for special case:
void set_element_impl(char** data, std::size_t i, const char* value) {
  std::size_t val_len = std::strlen(value);
  delete data[i];
  data[i] = new char[ val_len + 1 ]; …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is completely normal behavior. Floating-point numbers on a computer have limited precision. You're using float types which are also called single-precision floating point numbers, and the precision they have is usually about 7-8 significant digits. Your original number is around 30 and your error value is about 2e-6 which makes the relative error at about 0.67e-7 which is almost exactly the kind of error you should expect from using single-precision floating-point numbers (7-8 digits of precision). Get used to it, do not expect any floating-point calculations to be exact (they are only exact in a few rare cases). Doing numerical calculations on a computer is all about trying to limit the round-off errors (there is an entire field of computer science dedicated to this issue).

This also means that you should never to equal-comparison with floating-point numbers. That is, you should never do if(my_var == 0.0) but rather use this kind of test instead: if( fabs(my_var) < some_tolerance ) where you use some small tolerance value (e.g., 1e-5 to 1e-8 or so, depending if you use float or double).

The reason why 3D rendering code and libraries typically just use float as opposed to the more precise double is because precision is rarely a concern for rendering (it only needs to be as precise as the eye can distinguish, which is not precise at all) and speed is more critical.

DeeperShade commented: An awesome person and a shocking beard. ;) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Welcome!

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

First you're speaking about what you obviously don't seem to know.

I know a lot more than you think, it's just that I have an outside perspective, which is critical in being able to evaluate something objectively. Like with anything else, when you are too immersed into something, it becomes difficult to take an honest look at it, and religion is especially immersive and thus difficult to evaluate from an objective perspective when you are in it. Dismissing the opinions of someone giving you an outside perspective on a matter is never a good idea.

Second with all respect, Islam isn't Christianity or any other religion. Many principles in Islam do not apply at all to other religions.

Ohh, you'd be surprised how incredibly similar it looks from the outside. By the way, Christians would claim the exact same thing you do. In fact, I could probably take every word you wrote on this thread and simply change Allah for God and Muslim for Christian, and it would be really difficult to tell which is the original one. All religious folks claim there their religion has something unique, that their truth is deeper and more true, and that criticisms that apply to other organized religions don't apply to theirs, and so on so forth, but that is because they are too immersed in their religion and cannot take a step back and evaluate their religion the same way they evaluate others.

Third I'm not trying …

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

With my moderator hat on, I say:

Ignore Rash's post, he doesn't have the slightest clue what he's talking about, almost everything he said is wrong and misguided. Of course, you are free to use your code for personal projects or assignment submissions. And you still own copyrights to your code.

Sorry for the inconvenience (or scare), Rash is just throwing a tantrum against the terms of services. Why he would inflict this on innocent posters is beyond my comprehension.

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

With my moderator hat on, I say:

Ignore Rash's post, he doesn't have the slightest clue what he's talking about, almost everything he said is wrong and misguided. Of course, you are free to use your code for personal projects or assignment submissions. And you still own copyrights to your code.

Sorry for the inconvenience (or scare), Rash is just throwing a tantrum against the terms of services. Why he would inflict this on innocent posters is beyond my comprehension.

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

With my moderator hat on, I say:

Ignore Rash's post, he doesn't have the slightest clue what he's talking about, almost everything he said is wrong and misguided. Of course, you are free to use your code for personal projects or assignment submissions. And you still own copyrights to your code.

Sorry for the inconvenience (or scare), Rash is just throwing a tantrum against the terms of services. Why he would inflict this on innocent posters is beyond my comprehension.

happygeek commented: Well said +11
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Look at the standard function std::remove.

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

In your opinion what is a better language. C or C++.

It is highly dependent on what you do. C can certainly be simpler and hassle-free when doing some simple tasks (or low-level tasks). But C rapidly becomes difficult to manage on larger applications. I love software engineering, and C++ is awesome for that.

I mean this for operating systems to embedded software, deivce drivers, games and networking.

It is mostly a matter of size and complexity of the system. Embedded software and device drivers are usually very small programs and require quite a bit of low-level tricks (bit-wise operations, and setting hardware registers and interrupts), so, C is definitely the way to go (often the only choice, aside from assembly). Games and networking is almost entirely in C++ because these kinds of software are much more complicated structurally and require the kind of higher-level constructs that C++ allows you to do, but there are also other high-level languages used in those fields (interpreted or scripting languages, like C#/Java, PHP, Python, etc.). Operating systems (and compilers) are a bit of an exception here, most of them are entirely written in C (with some assembly), but these are large and complex systems that probably ought to be programmed in C++ (still, with many low-level components in C), but these are also very old and robust systems that cannot be changed overnight.

And is C++ so called OOP really going to be a bigger hit then C?

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

How useful is assembly? That's hard to say. Nowadays, it would be madness to write a large / complete application in assembly.

As far as I know, when it comes to writing assembly code, the only areas of application are in high-performance, low-level, and/or resource-restricted environments. I'm talking things like small micro-controllers (e.g., PICs) where assembly is the only option, and possibly in larger micro-controllers that usually support C (or BASIC) but assembly will be faster given the very limited resources. Then, there are things like hardware drivers and other low-level components (e.g., bus controllers, etc.). And finally, core functions that need to be highly optimized, usually small functions that get called an enormous amount of time like some kernel functions in an operating systems. I've also heard that there can be quite a bit of assembly programming in computer game programming, mostly in squeezing every clock cycle out of rendering code and programming shaders and other GPU processes.

All of these applications are highly specialized and you would probably end up having to learn assembly if you end up doing one of these things, but it is not worth learning to be proficient in assembly if you don't see a need for it in the very near future. Writing assembly is not fun, it's just very tedious to do. And it's not particularly difficult either (it's a very simple language after all!), it doesn't take very long to learn it, but don't do it for fun, only by necessity.

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

Just an additional hint, you don't need to sort the elements to do the removal as asked in the exercise question. Read the question again and see if you can't find a better way to do it, without having to sort the elements. Remember, sorting takes O(N logN) time to execute, but this removal problem can be done in O(N) time.

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

To clarify, if I understand the process, you have normals for all faces and then you need to generate a normal for each vertex, presumably as the average of the normals of the faces to which the vertex belongs (one vertex connects multiple faces).

I don't think there is any good way to do it by iterating through the vertices and finding the faces they belong to. You must do it the opposite way, iterate through the faces and accumulate vertex normal vectors for each of their vertices. Something like this (pseudo-code):

// initialize all vertex normals to 0.
for(std::size_t i = 0; i < texvert.size(); ++i) {
  texvert[i].nx = 0.0;
  texvert[i].ny = 0.0;
  texvert[i].nz = 0.0;
};

// accumulate the face normals in the vertices
for(std::size_t i = 0; i < facelist.size(); ++i) {
  texvert[ facelist[i].p1 ].nx += normal[i].x;
  texvert[ facelist[i].p1 ].ny += normal[i].y;
  ...
  texvert[ facelist[i].p3 ].nz += normal[i].z;
};

// re-normalize the accumulated vertex normals: 
for(std::size_t i = 0; i < texvert.size(); ++i) {
  double n_mag = std::sqrt( texvert[i].nx * texvert[i].nx
                          + texvert[i].ny * texvert[i].ny
                          + texvert[i].nz * texvert[i].nz );
  texvert[i].nx /= n_mag;
  texvert[i].ny /= n_mag;
  texvert[i].nz /= n_mag;
};

That should do the trick nicely.

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

Let me retort a bit here. The point of view you expressed is exactly what I've always understood the Muslim's view-point to be and how I have perceived my muslim friends, but that's bad, and that's the problem, and thinking that this point of view is OK is even worse.

1- Islam encourages and orders Muslims to read and learn and discover everything around them in the universe. The first word that was sent to the Prophet of Islam, Muhammad, was "Read!". There are also many verses in the Qur'an that order Muslims to search around them and try to discover what's in human bodies, Nature and the whole universe. Learning science is part of Islam. And God will judge Muslims who don't learn if they can.

That's alright, but not good enough. Science is the practice of skepticism. It is not something you learn in a book or read about. The fundamental requirement to be able to learn about the world around you and to discover truth is to never believe anything if you don't have sufficient evidence to support it. You cannot build knowledge any other way, every "fact" or discovery has to be supported by enough evidence to be able to add it to the accumulated knowledge in science. So, it is good that the Qur'an encourages people to "search around", but if it doesn't teach you how to do this rigorously (i.e., the "scientific method"), then it is of no use. My guess is …

Reverend Jim commented: Well thought out and expressed. +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You should go under Windows. Then, use the Windows partition manager to shrink that last partition (~480Gb) such that there is between 30-50 Gb of free space (or more, depending on how much stuff you want to install/use Ubuntu for). Then, boot into the liveUSB to install Ubuntu. When you get to the partition menu (from selecting "manually configure partitions") and you should see the free space in that list. Select the free-space. You should then be able to create a swap space and a partition for the root. Make sure you select the new root partition as the "Device for bootloader installation". Then, proceed through the rest of the installation.

Finally, you boot back into Windows and use EasyBCD to add the Ubuntu entry to the boot loader. Follow these instructions (the second part).

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

Nobody expects a typedef to be a reference type, so you should never ever do that.

Making a const-reference or reference typedef is a fairly common thing. I don't think the "nobody expects" and the "never ever do that" are appropriate (if ever).

With that said, I do understand your concern that the const-reference typedef might make it look like not a reference. That could be solved by just not having the typedef and instead forcing the user to do something like const locked_ptr& s = my_str.lock(); instead. It's a tradeoff between syntax sugar and explicitness (if that's even a word). That typedef in this particular case might not be appropriate, but it's a debatable issue, and somewhat a matter of preference too.

instead having a constructor on locked_ptr which takes a lockable<T>& argument, is more clear and more ordinary. That's why, for example, std::unique_lock<T> works that way, and why std::mutex::lock is a dumb method that returns void.
Also, even if we wanted to keep the interface the way it was, you just need to make locked_ptr's move constructor public, and then you don't need the typedef to be a const reference.

That is certainly a viable alternative, but I still prefer my way. Because the purpose of my locked_ptr is to obtain a lock within a function body (or inner-scope within a function) and restrict the locking to that function body only, and not allow any other uses of locked_ptr. A unique_lock (or unique_ptr) …

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

can't get to the bios either because no keyboard that works.

I guessed that. This is weird. Is your keyboard special? If it is, then try a very basic USB keyboard (with no fancy features). Having no keyboard available during the bios / bootloader phase is not normal, nor acceptable. It must be a problem with your computer model.

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

Thanks Rash for the in-slot of comments on my code snippet! Let me response:

Having a variable named l is a bad idea.

I agree, but in such a small example where it is not hard to see the context, and within a "detail" class that shouldn't be looked at by users, I don't think it's that bad. But, yeah, it's a bad example to give.

Overloading the address-of operator is a terrible idea.

The alternatives are worse. The idea here is that the lockable variables act as a "normal" variable which can only be accessed by a pointer to it, it seems to make sense to use the address-of for that purpose. But your right, I should have used a function name like "lock()" instead.

Putting semicolons after function definitions is an idiosyncracy that you'll abandon someday.

That's just a reflex of mine. Sometimes it is necessary, mostly it is not, but who cares?

Defining the type as detail::locked_ptr_impl for no reason is another, it could have just been locked_ptr and you wouldn't have compatibility problems.

The reason for having locked_ptr and detail::locked_ptr_impl is because it uses the "scope-guard" technique. Look at it again, and you will see that those two need to be separate, because locked_ptr is not just a typedef for detail::locked_ptr_impl, it is a typedef for const detail::locked_ptr_impl& and that makes all the difference in the world.

swap(lockable<T>&, lockable<T>&) is broken.
It doesn't work properly when …