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

But does the compiler-generated move-constructor nulls out the source object?

No. Because what does it mean to "null out" the source object? There is no clear and general answer to this, it is a matter of context. For some objects, it is useless to "nullify" it (as in, set it to zero). For some objects, it would be erroneous to do so. And for other objects, it would correct.

For the compiler-generated move-constructor, the rule is pretty simple. If you have a class like this:

class Foo {
  public:
    Bar1 a;
    Bar2 b;
    //.. some member functions and stuff..
};

Then, the compiler-generated move-constructor will be exactly equivalent to this:

  Foo(Foo&& rhs) : a(std::move(rhs.a)), b(std::move(rhs.b)) { };

It's that simple. It will just use the move-constructors of all the data members of the class. This solves the problem of having to know how to move an object (nullify the source or not). The assumption here is that if you don't provide a move-constructor (or explicitely delete it), then the compiler can assume that it is correct to simply move all the individual data members (with their appropriate move-constructors). This is exactly the same assumption as for the compiler-generated copy-constructor, if you don't provide one, the compiler assumes that it is OK to simply copy the data members individually. In the case of a resource-holding class, like the int_vector in my tutorial, this assumption does not work, i.e., it is not safe to simply …

abdelhakeem commented: Very helpful explanation! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

If you allocated the arrays dynamically, then you don't have an array object to pass to the function, you only have a pointer to the first element of an array. In other words, the only option you have is to pass by pointer. If you store your 2x2 or 3x3 arrays as arrays of arrays, then you must have a pointer to a pointer. In other words, you'll have code that looks like this:

void printArray(float** p, int N, int M) {
  for(int i = 0; i < N; ++i) {
    for(int j = 0; j < M; ++j)
      std::cout << " " << p[i][j];
    std::cout << std::endl;
  };
};

int main() {
  float** p = new float*[3];
  for(int i = 0; i < 3; ++i)
    p[i] = new float[3];

  for(int i = 0; i < 3; ++i)
    for(int j = 0; j < 3; ++j)
      p[i][j] = i * 3 + j;

  printArray(p,3,3);

  for(int i = 0; i < 3; ++i)
    delete[] p[i];
  delete[] p;

  return 0;
};

That's about all there is to it. If you have any questions, please ask.

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

The correct ending for your main function is this:

  delete iVector1[0];
  iVector1.at(0) = new Test(21);
  delete pVec1->at(1);
  pVec1->at(1) = new Test(22);

  for(int i = 0; i < iVector1.size(); ++i)
    delete iVector1[i];
  for(int i = 0; i < iVector2.size(); ++i)
    delete iVector2[i];
};

As for the linking error, this is not an error in the code, but an error in the linking. Did you define the destructor of your Test class in a cpp file? If you did, you must compile both cpp files together (the cpp file with the main function and the one with the implementations of the functions of the Test class). The linking error simply means that the compiler cannot find the definition (implementation) of the destructor of the Test class.

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

@BDazzler: The algorithm you described is basically called the Bug Algorithm, because it is as intelligent as a bug, but it works. Good and simple suggestion for a simple check if there is a path. And some simple robots even use this algorithm, like the Rumba (robotic vaccuum cleaner), because it is so simple, requires very crude sensors, and it is actually guaranteed to work (albeit slowly).

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

This problem is related to a classic issue in software engineering, called "Double Dispatching". Many of the most prominent people in the computer science field have discussed this problem, and it seems there is really no generally scalable (non-exponential) solution to this problem, other than converting everything to some common type that can represent everything.

In C++ with templates, this is a non-issue because you can template the functions in terms of the other type, and let the compiler do all the work of generating the different combinations (which are indeed exponential in number).

So, the problem you are reporting is really quite specific to a limitation in the "generics" provided by Java/C#. As far as there being a scalable solution, I doubt there is, unless Java/C# allows for the kind of class template member function templates that C++ allows for.

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

As an online resource, this site is pretty much unbeatable.

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

Definitely, put the task on the scheduler. Would you really expect the computer it is running on to run continuously for 2 months? Especially on a Windows system.

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

If you want an answer, you must reduce the problem down to the more essential parts of the code, and provide more details as to what the problem actually is. You can't expect people to go through all this code and figure out by themselves what the problem is, and eventually suggest a solution. If you could point more directly at the errors and provide more details as to what it does and what it should do (or what you expect it to do).

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

C++ by itself is not built-in with such graphical tools. You need to use a library and toolkit for Graphical User Interface (GUI) programming. Depending on the environment you are working in (windows, linux, mac), there are different options. And, in general, it is difficult to use these libraries without a fair amount of knowledge in object-oriented programmin in C++.

The tool that I would recommend in Qt. You should use their IDE program (Qt Creator) and try to follow some simple tutorials (there are plenty to find by googling). But, of course, Qt, like all other GUI libraries that I know, is object-oriented, so, if you are completely new to C++, it might be hard to pick up on. For advanced plotting, you should use Qwt (add-on for Qt), but for basic drawing of points, just the QWidget/QPainter components should do just fine.

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

Here is the thing with the "drawing a line". Draw a simple cartesian plot. Consider that 1 = true and -1 = false. Put a dot in the graph for each possibility (1,1), (1,-1), (-1,-1), (-1,1). According to XOR logic, only the points (-1,1) and (1,-1) yield "true" after a XOR. Can you draw a single line on that graph such that the two "true" points are on one side of it and the two "false" points are on the other?

The point with perceptrons is that all they can do is compute a linear combination of the inputs and use that to fire a 0 or 1 output (or through some other basis function). A "linear combination" is another word for a line, in fact, a line is defined by a linear combination of the coordinate variables (in this case, the coordinate variables are the inputs). So, literally, the only thing that a perceptron can do is draw a line and tell you on which side the input lies (0 or 1). So, this is why we say that a perceptron can only deal with a linearly separable problem, because that's all a perceptron does.

If you have a second layer in your ANN, you can get it to do two linear separations (e.g., two lines) and then combine those two outputs to figure out if the XOR output should 1 or 0. So, with one hidden layer, you can solve the XOR problem. It's that simple.

You must …

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

The problems you are reporting is not a matter of compiler issues, it is simply the fact that you don't understand that code that is built and made to link to MSVC compilers cannot link with code that you compile with GCC (used by CodeBlocks, through the MinGW port of the Unix-based GCC compiler).

As far as having a compiler that makes everything easy, well, you are not going to get that, not under Windows. There are only a few good compilers (ICC, MSVC, GCC, CLang, Comeau, BCB, etc.) and they all use either GCC's linking standard (which is the POSIX standard (as in Unix/Linux)), or they use MSVC's linking standard, or they use their one (like BCB), and none will be easy to work with, because Windows is a crappy development environment.

Things related to this will get easier as you get to understand how the whole process works (building, compilation, linking, loading, etc.). This is just something you need to learn, it is part of the technical details to know. Once you know them, you won't try to do outlandish things like linking a .lib file to a GCC project.

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

I hope you liked my tutorial, except for that one confusing part!

Isn't the compiler-generated copy constructor called if I used an rvalue like int_vector(int_vector(5))

No. The compiler-generate move constructor will be called if you used an rvalue like int_vector(int_vector(5)). In C++03, it would be the copy-constructor (and that explains the output from codepad) that is called, but not in C++11.

and it gets a shallow copy of the temporary object just like the move constructor?

Move-semantics is not the same as a shallow copy. A move-constructor will move the resource ownership from the source to the destination (constructed object). A shallow-copy doesn't move the resource ownership, it duplicates it, which is wrong. So, the shallow copy is only the first step in a move-constructor, the second, and crucial, step is to nullify the state of the source object. You need both steps. The default move-constructor will do the following:

MyClass(MyClass&& rhs) : member1(std::move(rhs.member1)), member2(std::move(rhs.member2), ... { };

In other words, it moves all the data members from the source object to the destination, and, of course, if a data member is of a primitive type (like int, float, or any raw pointer type), it will simply be copied. That is why you need to define your own move-constructor if you hold a resource like dynamically allocated memory, which is the point of my tutorial and the "Big Five".

I also thought that initializing the object with

int_vector(<temporary object>)

would call

int_vector::int_vector(const int_vector& …

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

The line that is outputted by "last reboot" is not the time of the last reboot but the time since when the reboots have been recorded:

wtmp begins Wed May  9 15:23:19 2012

For example, if I run the command on my laptop that I'm using now, I get this:

reboot   system boot  3.0.0-19-generic Sun May 20 16:23 - 18:18  (01:55)    
reboot   system boot  3.0.0-19-generic Fri May 18 13:16 - 17:58  (04:42)    
reboot   system boot  3.0.0-19-generic Mon May 14 23:12 - 00:06  (00:54)    
reboot   system boot  3.0.0-19-generic Fri May 11 14:06 - 18:23  (04:16)    
reboot   system boot  3.0.0-19-generic Thu May 10 16:45 - 18:08  (01:22)    
reboot   system boot  3.0.0-19-generic Wed May  9 14:58 - 18:27  (03:29)    
reboot   system boot  3.0.0-19-generic Tue May  8 10:48 - 17:55  (07:07)    
reboot   system boot  3.0.0-19-generic Wed May  2 15:43 - 18:49  (03:05)    
reboot   system boot  3.0.0-17-generic Wed May  2 15:14 - 15:42  (00:28)    

wtmp begins Tue May  1 16:24:48 2012

Clearly, if there was no reboot between now and the time from which the reboot records are still kept, all the "last reboot" command will output is the last line which tells you when the recording began.

You can trust what the "w" or "uptime" or "cat /proc/uptime" give you, which are all the same, and they give you the time since the last time the computer started (e.g. the "up-time").

As for the boot.log, this is likely only recording exceptional boot-related occurrences. For instance, on my computer, there is no such …

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

there is also something called task manager, (which i doubt linux has) and a key combination known as Ctrl+C

Linux does have a task manager. Many different GUI-based task managers exist, depending on the distro. And, a series of command-line tools exist to do task management work, like ps (list processes), kill (kill a process), and top (monitor processes), and because you can do this from the command-line you can still do it even if the desktop environment has crashed (which is really rare), something windows cannot do.

And the CTRL-C or CTRL-Z to kill a command-line application (or console app) is actually part of a larger set of key-combinations that date back to Unix. In windows command prompt, it only provides a few of them, like CTRL-C. Under Linux, you have access to many more (more than I know), like CTRL-C (send kill signal to the process), CTRL-Z (halt the process right away), CTRL-D (detach the output of the program from the current terminal / console, i.e., run the app in the background), etc. etc.

Linux has nothing to envy windows on this front. In fact, for all sys-admin and all "having control on your computer" tasks, Linux leaves Windows in the dust, mostly thanks to the robust GNU tools with their long-standing and stable Unix background.

There is a reason for Linux being free, don't you understand?

Free and open-source software has a big advantage over commercial one, it is the only scalable model …

broj1 commented: Agree with every statement here +4
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

AD-star is not the most well-known algorithm amongst lay-people, but Likhachev's papers on the subject are quite easy to follow. I do recommend that you understand / use / implement A-star first, which enjoys a very wide amount of material out there to explain it in details. The wiki is a pretty good starting point. There are also many implementations of A-star available. If you dig good implementations at a high standard of programming, you can check out the A-star implementation in the Boost Graph Library. Similarly, if you want an AD-star implementation (exactly as described in Likhachev's work) in the same style and standard as the BGL A-star, you can check out my implementation of that here.

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

So, if I get this right, you want to train an ANN to be able to determine if there is a path between the current player position and the target. Frankly, this is not going to work. You would need a very deep ANN to get this working (deep means with many hidden layers) and such ANNs are exponentially difficult to train (that's why most ANNs don't have more than zero or one hidden layer).

This is an especially bad idea in light of the fact that there is a very simple algorithm to solve your problem quickly and efficiently. The AD* or Dynamic A* algorithm would work very easily for this, or even just a vanilla A* would solve your problem much faster and easier than any ANN or GA method.

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

game and simulation degree from DeVry University

Sounds like a scam to me (in fact, DeVry, in particular, have been in and out of courtrooms for years for scam-like behavior). Stay away from these for-profit colleges. When they boast numbers like 90% employment in "related" fields after graduation, it may seem high, but it is actually not more than what a high-school degree will get you (when you talk of about 5-10% unemployment in high-school graduates... you do the math!). They take your money and give you very little in return. The quality of the profs is dubious at best. And if I were in a management position and saw a title like that "game and simulation degree from DeVry University", I would be very skeptical, and would probably just move on to the next CV in the pile. People who hire generally know the schools and universities that are established and are known to produce good graduates (which are not necessarily the more expensive places). I'm pointing this out because it does matter. And also, a degree title like "B.Sc. in Computer Science" is something people know, understand, and expect to be genuine (and up to a good university standard).

I think your prof has given you sound advice. Go in computer science, and cultivate your interest in game programming by making course projects and extra-curricular projects within that field. Remember that having a genuine degree and good grades only gets the potential employer to keep on …

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

You don't need to "obtain" a software license from anywhere. When you are the author of a piece of software, you automatically have the copyrights to it (copyrights just mean that you get to decide who can use it, to what extent, for what purpose, and for what price). Now, if you want to distribute your software, you need to give a permission to people for using it, including the terms by which they can use it, and this is called a license. It is no more than a text that describes the terms (or rules) for the user. So, when you talk about licenses like BSD, GPL, LGPL, Apache, etc., it is really referring to a standard text that describe the terms, a text which has been written by lawyers (and other law-savvy people) and have sometimes been used or challenged in court (and have won). In theory, you could write your own license terms, but if you are better pick a standard license text that has been proven to be legally valid and can stand up in court if the need arises.

I don't know any widely used closed-source freeware license, but I would imagine there are plenty. You can look at prominant freeware licenses (like Acrobat Reader, or Winamp) and see which fits you the best. And again, "obtaining" the license is just a matter of picking a license text (set of terms) that fits your needs and to attach that text to your software (like most …

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

I think that your design is somewhat flawed. First of all, you require the catcher to know and require that the exception is one that is being logged, which you may not always want to do and may not be able to do in certain cases, leaving your catch-clauses very heterogeneous. Second, exceptions are common-place during the execution of a program, they aren't used only for completely erroneous occurrences, they are a mechanism to report out-of-the-ordinary conditions (and roll-back changes), which are sometimes quite common. Third, in your current implementation the thrower of the exception just throws a normal exception, and the catcher decides if the exception will be logged. I'm not sure that this is the best thing, but you can argue either way (that the thrower or the catcher should make that decision). Finally, as a general rule, you should keep the operations that occur during the propagation of an exception as simple as possible, to reduce the risk of a second exception being thrown, which would lead to an abort of the program (immediate termination). Also, opening and closing a file each time you want to log a message is too much stuff to do.

In light of these things, here is a somewhat more "professional" implementation of an exception-logger (while keeping it simple):

#ifndef EXCEPT_LOGGER_HPP
#define EXCEPT_LOGGER_HPP

#include <iostream>
#include <type_traits>

// Create a singleton class to access the logger's ostream.
class except_logger {
  private:
    std::ostream* destination;
    static except_logger& get_instance();
    except_logger(std::ostream& dest = std::cerr);
  public: …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

QWERTY here too.

I'm afraid your friends might be right, you are abnormal.

Personally, and especially for programming, I find that the placement of the non-letters in a QWERTY layout has more of an impact (and that is not significantly different in dvorak). With code-completion, you don't end up writing that many complete words, even if you choose good long and meaningful variable names. What you do type often is []{};:.<>!&% which are often different on different layouts, and that's really annoying when you use different computers, possibly in strange countries. And also, language plays its part, I can't use a layout that doesn't support french letters (accents and cdilles).

Is there a special keyboard layout that is really tailored for programming with easier-to-reach symbols that are common to most programming languages? I don't think dvorak qualifies.

|-|x commented: this.very(true); +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Agent -> Bond

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

For templates, the definitions of the functions must appear in the header file, if they are too long you can simple put them outside the class declaration, but still in the header file (i.e., after the class declaration). This is one of the few major drawbacks of templates.

Read this FAQ.

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

You don't need to use variadic templates for this. And you certainly don't want to go with the var-args solution that was suggested.

There is something called std::bind and std::function. The first allows you to bind any number of arguments to a function pointer and basically transform that function pointer into a different signature (and supply additional arguments). The second is a more general wrapper for all types of callable objects (function pointers / references, member-function pointers, functors, etc.), and that is the output of the bind function. In other words, you can do something like this:

double PNorm(double d1, double d2, int p) {
  return std::pow( std::pow(d1,p) + std::pow(d2,p), 1 / double(p) );
};

double Norm2(double d1, double d2) {
  return std::sqrt( d1 * d1 + d2 * d2 );
};

std::vector<double> GetNorms(const std::vector<double>& v1, const std::vector<double>& v2, std::function< double(double,double) > norm_function) {
  std::vector<double> result(v1.size());
  for(int i = 0; i < v1.size(); ++i)
    result[i] = norm_function(v1[i],v2[i]);
  return result;
};

int main() {
  std::vector<double> v1, v2);
  v1.push_back(0.5); v2.push_back(0.8);
  v1.push_back(2.0); v2.push_back(4.0);

  v_n2 = GetNorms(v1, v2, Norm2);
  std::cout << "Norm-2 are: " << v1[0] << " " << v2[1] << std::endl;

  v_n5 = GetNorms(v1, v2, std::bind(PNorm, _1, _2, 5)); // the _1 and _2 stand for argument one and two from the destination function signature.
  std::cout << "Norm-5 are: " << v_n5[0] << " " << v_n5[1] << std::endl;

  return 0;
};

I hope you get the idea. Read the cppreference pages on the subject, these things are also available …

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

The first problem:

inline ostream& Point::operator << (ostream& Str, const Point &PT)
{
    Str<<"("<<PT.X<<", "<<PT.Y<<")";
    return Str;
}

Should be replaced by:

ostream& operator << (ostream& Str, const Point &PT)
{
    Str<<"("<<PT.X<<", "<<PT.Y<<")";
    return Str;
}

The point is that when you declare a friend function within a class, what you are doing is declaring a free-function (not a member function), within the namespace that the class is in, which has access to all the private members of the class (this also means that if you don't need the function to be a friend of the class, don't make it one, just make it a normal free-function). In any case, a free-function does need the Point::. Also, because you put the function in the cpp file, it makes no sense to put the inline keyword there (but if you decide to put the function in the header, which you might since it is short, then you can put the inline keyword).

For the second problem with this line:

inline ostream& operator << (ostream& Str, const CustomType &CT);

the problem here is that you are declaring this operator as a member function of CustomType, and you are giving it two arguments. This is impossible and incorrect, and the source of all the troubles. Either you replace the inline keyword here with the friend keyword, and do as above. Or, you move it out of the class declaration (as a normal (or non-friend) free-function).

That should …

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

I agree with pyTony, you should start by getting the human-human game working. You should structure your code such that you can easily swap one human player for a computer player. For example, if you had a function like this:

enum PlayerID {
  BlackPlayer,
  WhitePlayer
};

PlayerMove GetNextHumanPlayerMove(const CheckerBoard& board, PlayerID id) {
  PrintCheckerBoard(board);
  int init_pos, next_pos;
  std::cout << "Which piece do you want to move?" << std::endl;
  std::cin >> init_pos;
  while(!IsSquareOccupied(board, init_pos, id)) {
    std::cout << "You do not have a piece at that square! Select a new piece..." << std::endl;
    std::cout >> init_pos;
  };
  std::cout << "Where do you which to move this piece to?" << std::endl;
  std::cin >> next_pos;
  while(!IsMoveValid(board, init_pos, next_pos, id)) {
    std::cout << "This move is not valid! Select a new destination..." << std::endl;
    std::cin >> next_pos;
  };
  PlayerMove result;
  result.initial_position = init_pos;
  result.destination_position = next_pos;
  return result;
};

The above function will work for both human players, and you can also see from it the kinds of sub-functions that you might want to do (PrintCheckerBoard, IsSquareOccupied, IsMoveValid, etc.) and the kinds of data structures you might want to create (PlayerMove, CheckerBoard, etc.). Also, if you want to create a computer player, you can easily make an alternate function with the same signature, as so:

PlayerMove GetNextComputerPlayerMove(const CheckerBoard& board, PlayerID id) {
  // insert some code here to analyse the board and find the best next move.
  // return the best next move that was found.
};

This way you …

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

How can I get my program to do that for me?

That's what CMake does!

This is the typical process from writing some code in an IDE to getting it into an executable:

  • Use the text-editor (or text-editing part of the IDE) to write some code and save them to files (headers and cpp files, or others);
  • Use the configuration menus to setup things like:

    • Include-paths to look for the #included headers;
    • Compilation options (optimizations, language standard, and other more advanced things);
    • External libraries to be linked to the project (the .lib, .a, .dll and .so files needed by the project);
    • Warnings to be enabled / disabled (should enable all by default);
    • Whether it is a Debug build or a Release build;
    • Destination directory for final executable or DLL, and directories for intermediate output file (object files);
    • etc.
  • Click on the "Build" button (or "Run") which triggers the IDE to:

    • Generate a build script from all the given configurations;
    • Execute the build script through a back-end console or terminal (or shell);
    • Redirect the output of that back-end console to display it within the IDE in one way or another (either a simple reprinting of it to a text-box, often below the coding area, or parse it to collect the errors and warnings into some list-view or something like that);
  • If the build is successful, run the executable (if any).

Once you get the text-editing part working, with code-highlighting and whatever else you want, …

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

Visual studio comes with a command prompt application to replace the cmd.exe from Windows. That visual studio command prompt is basically the same as the cmd.exe except that it initializes all the necessary environment variables when it is started. I see no reason not to use it since it doesn't require you to launch Visual Studio and it is basically the same tool as cmd.exe (which is a shit command prompt program anyways). You also might want to look at Windows Powershell (it's free) which replaces cmd.exe with a much more powerful (more Unix-like) shell application (it has things like pipes, regular expressions, folder stacks, etc., which actually make it a useful shell, as opposed to cmd.exe which is complete crap).

Otherwise, you can use a batch file that comes with MSVC which sets up all the required environment variables. See the instructions here. You just have to run this batch file each time you start the command-prompt (which is basically what the Visual Studio command prompt does, but automatically).

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

Not only that but I'd have to constantly switch back and forth between headers and sources to see whats declared where or what contains what.

If it annoys you to switch back and forth between the header and source when you are implementing the functions, then here's a trick for you. Simply write the code in the header file (within class declaration), so you won't have to switch all the time, and then, once you have finished implementing and testing them, copy all the longer functions (longer than a few lines) into the source file, clearing them from the header file.

But now I'm looking up all my habbits to see if they cause performance degradation and I've read the first one does whereas the second doesn't :S

That depends on your definition of performance. The first one (definitions inside the class declaration) will lead to faster code at run-time, but possibly a larger executable at the end too. The second one will lead to faster compilations and fewer compilation dependencies (fewer needs for complete recompilations).

I'm also reading that if i put my definitions inside the class, it's automatically inlined

Putting the definitions inside the class will make the compiler attempt to inline the function by default. Inlining is never guaranteed, it is always up to the compiler to make that decision, whether it is worth inlining or not. And btw, inlining is a good thing, it is one of the most important …

triumphost commented: Very Very Amazing Post. I'll Change all My Files Now. +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

How does Notepad++ do it

Notepad++ uses Scintilla as a back-end for the syntax highlighting and other coding-related features (code completion, etc.). Most IDEs and enhanced text editors (like Notepad++, emacs, vim, etc.) use only a limited number of libraries that do the actual syntax highlighting. There is no reason to reinvent the wheel, many syntax highlighting engines are available that can take raw text and produce a markup output that has all colouring in it, others will handle the entire text-editing too.

Most projects like this just start off simple and build up over the years. Basic syntax highlighting is quite simple, just look for keywords for a given language (e.g., in C++, the list could be "for if else while do void int float double ...") and highlight them with the configured color or font. Once you do that, you can start checking for indentations, then record variable and type names and highlight those too, and so on, until you have a complete system.

Also how does codeblocks compile our programs.

Codeblocks does not compile programs. When you install codeblocks, it also installs MinGW which is a minimalist port for Windows of GCC (GNU Compiler Collection, which includes a C++ compiler amongst many other things). GCC is one of the oldest and most robust compiler suites out-there, and it is free and open-source (obviously, it's GNU). MinGW is a port for Windows, because GCC is primarily developed as a Unix (or Unix-like) …

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

Well, this line doesn't make any sense:

list == argv[3];

Neither does this one:

cout << *list << endl;

Maybe you should explain what you think these lines are supposed to do, because it doesn't seem obvious to me (nor for the compiler). The variable list is a vector of strings, it doesn't make any sense to compare it to a string or to dereference and print it.

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

Netbeans requires that you install the compiler separately (because it can work with different compilers). MS Visual C++ installs the MS compiler along with the IDE, that's why you won't have that problem with MSVC. If you also have MSVC installed, then you should be able to configure Netbeans to find it and use it. Otherwise, you can install MinGW (a windows port of GCC). You can get it here, and follow the instructions given on that page. Then, you'll have to get Netbeans to find the compiler (should be easy through menus or wizards). If you don't want to go through that trouble, just use CodeBlocks that comes with a MinGW installation, and is also a pretty good free IDE.

What is the beast language out there to get you hired?

That's too long to answer, and requires context as to what kind of jobs you seek (gaming, web-apps, database, server applications, scientific programming, etc., etc.). C++ is certainly a very good and generic choice, and does dominate some big areas (mostly high-performance and high-reliability software), and it is part of the languages you "need to know" to be a well-rounded programmer, but, in some areas like web development, C++ is virtually useless (beyond giving you a greater range of knowledge).

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

For the delete function, you have to do more or less the following:

  • Ask the user for the product name to delete.
  • Check if the startPtr has that product name

    • if it does, then delete the startPtr and set it to the next node, i.e., startPtr->nodePtr, and exit.
  • Loop through the nodes while keeping track of the previous node.

    • if the current node has the sought-after product name, then
    • set the previous node's nodePtr to the nodePtr of the current node
    • delete the current node and exit.
  • Print an error message saying that the node was not found.
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

doesn't seem to delete that block of memory properly - I tested this by making a temp pointer to it in my main function before the function call and then checking its value after the function call. Any tips?

When you do delete, it doesn't actually "erase" the memory. It only frees the memory, meaning that the memory is simply marked as being available for future dynamic allocations of memory, which might over-write it then. There is no point in erasing the memory (whatever that means.. setting all bits to zero?). So, after you delete the memory, you can still read it and get the same value as before it was deleted, however, any time soon, that could change because that chunk of memory could be allocated to something else, and, in any case, you are not "allowed" to read or write to that chunk of memory after you deleted it (and that could cause a crash under some circumstances).

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

You could use inheritance (OOP) but it would be very wasteful for such small attributes.

Basically, what you need is a class template like Boost.Variant as your "NAttrib" implementation, while your FloatAttribute and ComplexAttribute can remain very simple (no template, no inheritance). This is fairly advanced and uses templates and overloading in non-trivial ways, of course.

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

The pointer oldArr within your function is not the same pointer as the one you pass to it (caller-side). The value (address it stores) is the same (copied when entering the function) but the pointer itself is not the same variable. What you need to do is pass it by reference, which means that the pointer within the function and the pointer that was passed to it behave as one variable. The syntax is as follows:

void enlargeArray(int *& oldArr, int arraySize);

Notice the ampersand & symbol after the star. This symbol indicates that oldArr is a reference to a pointer to an int. At the call-site, the syntax remains unchanged, within the function too.

Another alternative is to pass it as a pointer to a pointer, as so:

void enlargeArray(int ** oldArr, int arraySize) {
  //...

  delete[] *oldArr;

  *oldArr = newArr;
};

But then, you have to do this at the call-site:

enlargeArray(&oldArr, arraySize);  // notice & here, for getting the pointer to 'oldArr'.
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

This is annoying me, so let me rant a bit on this.

First of all, I think your caps-lock key is defective or something. Writing everything in upper-case letters just makes you look stupid, I'm sure that's not your intent, so you might want to get that fixed.

Second, this forum is not for pasting code, the site for that is pastebin.com. The main purpose of this forum is education and discussion, your post achieves neither. You just post code without even asking a question or for feedback on it, or spurring any kind of discussion.

The code that you posted is not helpful to anyone either. There are many problems with your code:

  • You use an antiquated, non-standard header: <conio.h>.
  • You use the pre-standard header <iostream.h> which should now (since mid-90s) be <iostream>.
  • You use pre-standard code in which the std-namespace doesn't seem to exist.
  • Your main() function should return int, not void, and that's an error on many compilers.
  • You use very old (C89) style of declaring all variables at the start of a function. This is a practice that is highly discouraged now, especially in the C++ realm.
  • Your indentation is horrible.
  • You pack your code very tightly with no spaces in-between things. This makes the code very hard to read, which is really bad for anyone who tries to learn from it, or tries to grade it.
  • You don't have any comments anywhere.
  • You use very short and un-intuitive names for your variables.
  • Your …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Blackjack is definitely more manageable. All you need is a random-number generator (the rand() function) to draw the cards (or a bit more than that if you want to draw cards from a actual deck with a finite number of cards, as opposed to an "infinite" deck of cards) and very simple logic for the dealer.

Checkers would definitely be harder because you need to keep track of all the pieces and display them on a board, but certainly manageable. But creating a computer opponent is out of the question for a week's project.

I can't say if a blackjack game would be enough to "impress" your prof. That really depends on the level of your course, but your initial description suggests that it is a very basic programming class, so it would probably be a reasonable project. A blackjack game is more difficult than a hangman game, but not by a lot.

You also have to keep in mind that the extent to which you can impress your prof often depends more on the quality of the implementation than on the end result. If you throw together a dirty piece of code that does the job it is not likely to impress much because it can look like the result of a trial-and-error methodology (which is really bad) or look like you don't understand how and why you should organize the code properly. For example, if I see a piece of code that does simple linear algebra calculations (matrix-matrix …

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

You need to first read the entire line as a single string, and then read off the individual numbers in it.

Because, when you read numbers from the file, it will ignore any non-number character (including the new-line character) that it encounters. So, there is no way to tell when the line ends. So, you have to first use another method to read the entire line, then read off the numbers from that.

To read one line from the file, you can use a string and the getline function, as so:

#include <string>
// .. same as in your code...

int main() {
  // ... 

  string oneLine;
  getline(inFile, oneLine);
  cout << "The first line is:" << endl;
  cout << oneLine << endl;

  //..
};

Once you have an entire line read from the file, you have to read the individual numbers. To read numbers from a string, you can use a class called stringstream (in header <sstream>) which acts the same as a file-stream class. So, you can do this:

#include <sstream>
// .. same as before ..

int main() {
  //...

  // after reading a line into 'oneLine':
  stringstream inStrStream(oneLine);  // create string-stream from the line-string.
  cout << "The individual numbers are:" << endl;
  while(!inStrStream.eof()) {
    inStrStream >> num;
    cout << num << endl;
  };

  // ..
};

I think you can figure out how to use the above codes to do your assignment.

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

Because the ratio between your longest and shortest hair is exactly 1.61803399.

Why does the flora from a Mountain produce fluorescent green carbonated water droplets in the morning?

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

Does ^ Replace the & operator?

No. The ^ is equivalent to *, while the % is equivalent to the &. Except that the ^ and % are for garbage-collected (or .NET) objects only. In other words, you allocate a GCed object with MyClass ^ obj = gcnew MyClass();. If you're going to do any C++/CLI, you should at least read up on the basics, the wiki page answers all the questions you asked so far.

triumphost commented: Very Very helpful. Solved it +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Layman: Hey dude, what's with the sad face?

Programmer: I had a programming competition this weekend, I ranked at the number 1 position...

Layman: That's great! Congrats! But why are you disappointed?

Programmer: I was aiming for the number 0 position!

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

The dot operator and member function call have priority over the dereference operator. This means that the expression *ptr.str.at(1) is evaluated as *(ptr.str.at(1)), and that is why you get the error "str" is not a member of the pointer type grid*.

To fix it, you just need parentheses, like so: (*ptr).str.at(1). Or, C++ provides a shorter syntax for this very common operation, which is as follows: ptr->str.at(1), where the arrow p-> basically replaces the (*p)..

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

This is what is called a signals and systems implementation (at least, that's how I call it..).

I had a similar problem a while back, when writing a piece of control software for a humanoid robot. This is actually not trivial to do correctly, as I'm sure you have figured out by now. I managed to get a decent implementation working, but it wasn't perfect (it would stall on rare occasions). My advice is to use a library for that. You didn't specify the language so I can't point you to one in particular (if you are using C++, then look at Boost.Asio or the new C++11 standard library for concurrency, especially futures and async).

I'm not an expert with this, but I can tell you how I did it. I had a class template for signals (of any type) which could be either set as synchronous or asynchronous, which meant that they would either provide the signal's value only when a new value is received, or provide the signal's value at any time when requested. Then, I would have classes that were derived from a System class. Each system object would run on its own thread, and would have a registry of input and output signal definitions (with properties like sync/async, required/optional inputs, name, type, etc.). Then, upon initialization of the structure of the software, I would connect the different systems by creating signals that acted as output of one system …

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

Sorting with respect to two things (SalesGrp and PartNum) in a way that if the first elements are the same, then sort with respect to the second element, that is called lexicographical sorting (and alphabetical sorting is a kind of lexicographical sorting, where each element is a character).

In short, all you need to do to is define a comparison operator (or function) to compare the two ProductSummary objects. Here is that function:

// a custom less-than operator for class ProductSummary:
bool operator <(const ProductSummary& lhs, const ProductSummary& rhs) {
  if(lhs.getSalesGrp() < rhs.getSalesGrp())
    return true;
  else if(lhs.getSalesGrp() > rhs.getSalesGrp())
    return false;
  else // this means both SalesGrp are the same:
    return (lhs.getPartNum() < rhs.getPartNum());
};

You have a lot of work to do to make your ProductSummary class work correctly. But when you get there, you can use the above less-than operator and the bubble-sort algorithm that you posted already, and that should be it.

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

First of all, the field in question is computational geometry.

Then, within that field there are volumetric representations and boundary representations (or B-Rep). Most B-Reps are parametric.

There are a number of fundamental representations used for curves and surfaces (and higher order geometries). Most are based on the construction of some mathematical formula (a high-order polynomial or some piece-wise continuous patches of lower-order polynomials (splines), or some other more isoteric representations) based on a set of control-points (or knots) which are either a part of the curve/surface or just points that sort-of pulls the curve/surface in different directions but do not lie on the curve/surface. Different representations are used in different contexts because they possess different qualities (smoothness, efficiency, uniform parametrization, meaningful parametrization (e.g. cord-length parametrization), etc.).

Here are a few methods of paramount importance (you need to understand them to go any further). Most method work for curves and can be extended to surfaces, but some are specialized for surfaces.

  • Splines: This is a piece-wise interpolation between two control-points (and higher-order information like tangent vectors and normal vectors at the control points). This method is basically just a matter of solving for a polynomial of sufficient degree to ensure that the end-points match the control-points (and their higher-order vectors). For example, in first-order, you would solve for a straight-line (or plane) between two points (or three surface points), but normally you go with a higher-order interpolation (cubic or quintic). The nice thing with splines is …
TrustyTony commented: Professional help, thank you! +12
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

If it makes sense, read it more than once and think about it differently each time.

If you read it again and again, and it doesn't allow you to think differently about it, then it is clear.
If you read it again and again, and it allows you think differently about it everytime, then it is mystical.
If you read it again and again, and it forces you each time to see it differently the next, then it is poetry.

codeorder commented: .impressed am I, for a .Clear and mystical impression, not poetry. (read that a few times xD) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

tussauds -> wax

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

Life is like a growing tree, your roots must run deep and strong, but it is only with far-reaching branches and healthy leaves that you can gather the sun-light needed to enlighten your life.

Mastication

codeorder commented: I definitely dig. :) +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Are you aware that union types can have constructors, destructors, and member functions (but not virtual ones). Maybe that can help you solve your problem, which I don't quite understand.

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

that once destroyed