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

Oh, sorry, it should be istream and ostream, instead of ifstream and ofstream. That should fix it.

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

I have a some libraries which have a lot of common classes but the namespaces are different. Most of the code I was writing could be easily reused by classes in both libraries so after some reading I tried a technique of using the templates to pass namespace.

That is a very ugly and awkward technique. I can think of a thousand better ways of achieving the same effect. One typical way is using a tag dispatching mechanism with meta-functions, as so:

struct dummy_type { };

template <typename Tag>
struct get_T1 { typedef dummy_type type; };

template <typename Tag>
struct get_T2 { typedef dummy_type type; };


namespace A {

    class T1 {
        public:
            int i;
    };

    class T2 {
        public:
            int x;
    };

};

struct A_tag { };

template <> struct get_T1<A_tag> { typedef A::T1 type; };
template <> struct get_T2<A_tag> { typedef A::T2 type; };


namespace B {

    class T1 {
        public:
            int i;
    };

};

struct B_tag { };

template <> struct get_T1<B_tag> { typedef B::T1 type; };


template <typename Tag>
class util{
    public:
        void print(const typename get_T1<Tag>::type& tobj)
        {
            std::cout << tobj.i << std::endl;
        }

        void print2(const typename get_T2<Tag>::type& tobj) {
            std::cout << tobj.x << std::endl;
        }
};

The above is a lot more elegant because you can declare, alongside your namespace declaration, what types you want to "expose" via a given "tag". You can even make a specialization for the meta-function (e.g., get_T1 and get_T2) to trigger a compile-time error if instantiated. …

Agni commented: Thanks for the alternate technique +8
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

You cannot use this type of thing:

movieFile.read(reinterpret_cast<char *>(&thisDVD), sizeof(thisDVD));

this is bad. You cannot just dump the memory of "thisDVD" into a file like that. You need to create a member function in the DvdInfo class that will save / load the file by saving individual data members. Something like this:

class DvdInfo {
  // ....

  void saveToFile(ofstream& OutStream) {
    OutStream.write(reinterpret_cast<const char*>(thisMovie.sTitle), strlen(thisMovie.sTitle) + 1);  // the '+ 1' is for the null-termination character.
    OutStream.write(reinterpret_cast<const char*>(thisMovie.sA1), strlen(thisMovie.sA1) + 1);  // the '+ 1' is for the null-termination character.
    OutStream.write(reinterpret_cast<const char*>(thisMovie.sA2), strlen(thisMovie.sA2) + 1);  // the '+ 1' is for the null-termination character.

    OutStream.write(reinterpret_cast<const char*>(&thisMovie.sYear),sizeof(int));
    OutStream.write(reinterpret_cast<const char*>(&thisMovie.sTime),sizeof(int));

    // ...
  };

  void loadFromFile(ifstream& InStream) {
    InStream.getline(thisMovie.sTitle, 126, '\0');
    InStream.getline(thisMovie.sA1, 80, '\0');
    InStream.getline(thisMovie.sA2, 80, '\0');

    InStream.read(reinterpret_cast<const char*>(&thisMovie.sYear),sizeof(int));
    InStream.read(reinterpret_cast<const char*>(&thisMovie.sTime),sizeof(int));

    // ...
  };

};

But, in general, I recommend saving and loading into a text format (not binary), because it's less trouble that way (and you can open the file in a text editor to see what it produced). And, of course, you call the save-load functions like this:

switch (mChoice)
    {
    case 1:
            thisDVD.loadFromFile(movieFile);
            while(!movieFile.eof())
            {
                cout << thisDVD.sTitle << " (" << thisDVD.sYear << ")" << endl;
                cout << "Starring " << thisDVD.sA1 << " and " << thisDVD.sA2 << endl;
                cout << thisDVD.sTime << " minutes" << endl;

                thisDVD.loadFromFile(movieFile);
            }
        break;
    case 2:
        if (dInfo.setInfo())
        {
            cout << "\n\nSaving the DVD information to the file..." << endl;
            thisDVD = dInfo.passInfo();
            thisDVD.saveToFile(movieFile);
        }
        break;
    case 3: …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

There is a conflict between your declaration of the struct Movie in the main file and in the DvdInfo class. I would recommend that you move the struct Movie declaration out of the DvdInfo class to just above it (still in the dvdinfo.h header). And remove the declaration in main file. As so:

#ifndef DVDINFO_H
#define DVDINFO_H

#include<string>
using namespace std;

struct Movie
{
    string sTitle, sA1, sA2;
    int sYear, sTime;
};

class DvdInfo
{
private:
    static int dvdCount;

    Movie thisMovie;
    bool isCorrect, doSave;
    char yesno;
public:
    // ....
};

#endif

and the main file:

#include "dvdinfo.h"
#include<iostream>
#include<string>
#include<fstream>
using namespace std;

void displayMenu();
void mFileIn();

int main ()
{
//...
//...    

The above fix will solve your problem about thisDVD = dInfo.passInfo();.

As for the error in setInfo() about cin and cout, that error is just because you have not included the <iostream> header in your dvdinfo.h header file. So, you need this:

#ifndef DVDINFO_H
#define DVDINFO_H

#include <string>
#include <iostream>   // notice addition here.
using namespace std;

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

The difference in total memory used between a vector or an array is going to be negligible (probably only one pointer and two integers).

The use of a vector is going to take a bit more time to allocate the memory because it must ask the heap to allocate a chunk of memory. But that's about it.

If you use a static array, it will be a faster because it is allocated on the stack. However, the stack has only a limited amount of memory available (usually 2 or 8 Mb), so, it is not really a good idea to take too much of the stack memory for large arrays. Every time you call a function, the local variables are allocated on the stack, taking up more and more of the stack memory, and so, that is why a recursive algorithm can end up running out of stack memory (called a "stack overflow").

In summary, the overhead of allocating the memory dynamically (using std::vector) is slightly more than using a static array, but it is usually negligible compared to whatever else you actually do with the elements in the array. And because you should avoid using the stack too much, it is usually better to use a std::vector for an array of any significant size.

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

You can use the "Widget" object, and a lay out. It's kind of hard to explain how to do this, but it is easy.

Say you have a main window. You can create a Widget that you put on it. Then, create a second Widget that you put on the main window also. Then, right click on the "MainWindow" (in the Object Inspector) and go to the "Lay out" menu and select the "Lay out vertically". This will cause the two Widgets to take half of the main window each, i.e., one filling the upper half, the other filling the lower half. At this point, you can set fixed sizes or whatever else if you want to change how the two Widgets split the main window. Finally, you can add whatever else you want in either Widget, like a QPaint object or whatever else.

You can also create many other kinds of lay outs, and they are very useful for placing different objects in different places. It is also good for automatically adapting the sizes of things when the main window is resized and stuff.

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

I don't know what the exact numbers are, but one thing is for sure, if you were to compile a sum of all the down-votes versus up-votes found throughout the database, you'd get an overwhelmingly positive count at the end. That speaks to the fact that we, human beings, prefer positive reinforcement as the main mechanism for learning to live in a community. That's great, but it doesn't mean that there's no place for the opposite mechanism too, i.e., the occasional slap on the wrist. I think that down-voting does have its place, because at times it is useful in ways that can't be substituted by other mechanisms. If I want to convey messages like "I strongly disagree with that", or "this post is a nuisance or useless", without necessarily demanding a ban or infraction or deletion of the post or anything that harsh, and without creating a flame war with the poster, then the down voting works well.

And down-votes do convey a message. I, like many other veteran posters, have an overwhelming amount of up-votes, but also a number of down-votes. A few times, I've looked through my list of "down-voted posts", and what I see there is usually two things: people who down-voted because they didn't like to be told that they needed to show some effort/work towards solving their problem and that we wouldn't just give them homework solutions; and a number of posts that I have made in the past when I was in a …

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

The problem is that your Forward_Euler method takes function pointers as parameters, but "f", "gleft" and "gright" are member functions of the class C. These are not the same thing and thus, you get errors.

There are a number of options to solve the problem.

1) You could make the Forward_Euler function take member function pointers, but then it must be member functions of class C. What I mean is that you'd need this signature for the Forward_Euler method:

Eigen::MatrixXd B::Forward_Euler(C& c_obj, double (C::*f)(double), double (C::*gleft)(double), double (C::*gright)(double));

And then, within that function, you would call the functions as so:

double a = c_obj.*f(1.0);
double da = c_obj.*gleft(1.0);

This solution might not be practical if you want to use that function with function pointers that are not members of the class C.

2) In the OOP style, you could create a base class for a class that contains these three functions, as so:

class DifferentiableFunction {
  public:
    virtual double f(double) = 0;
    virtual double gleft(double) = 0;
    virtual double gright(double) = 0;
};

And then, your C class would inherit from that base class, and then you can make the Forward_Euler method with the following signature:

Eigen::MatrixXd B::Forward_Euler(DifferentiableFunction& f_obj);

And call the function as this:

    if(fdtype == 'f')
        u = b.Forward_Euler(*this); 
    ...

3) You could make the Forward_Euler method to take in std::function objects (which are generic function wrappers provided by the more recent compilers (C++11)). As …

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

I realized that writing an essay is very important

Writing essays was fun. I particularly enjoyed taking the reader on for a wild ride, making sure my essays wouldn't be just another essay in the pile the prof had to grade (or the pile of cover letters for some job / scholarship application). It has worked wonders for me. I always had between 95 and 100 percent on all my essay regardless of my bad spelling / grammar or if I even read the book the essay was on. The real secret to a good essay is to think about the reader and making his/her experience the best possible when reading it.

Why did you pick this movie?

I don't know for sure, but knowing what the movie is about, there's a pretty good hint. The movie is about a bunch of blasé prep-school seniors who get inspired by this "passionate" teacher that teaches them about poetry and about some (hollywood-cliché) life-lessons, it's a classic passing-of-age movie. At the end, everyone is happy and changed for life, and tears flow on your cheeks as you watch the movie. Maybe LastMitch figures you're just the right age to be inspired by this movie, and I guess he could be right, but it's not like he would know anything about what you like, what you can understand or what "lessons" you need to learn about, just by knowing your age. And also, it's not like you need to …

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

Why are your listOfItems object vectors of vectors? From all your previous examples, it seems to me that it should just be vectors, as so:

std::vector<listA> listOfItems1;
std::vector<listB> listOfItems2;

And when you use that, it works fine. If you wanted to use vectors of vectors of object which also contain a data member that is a vector (or container of some sort), then you'll need to change the loops in the function (to have three nested loops, with only the most nested loop that uses the container referred to by the pointer to data member).

I'm also reading up on "pointer to data members"

Yeah, pointer to data members are not very popular / well-known. They are generally not that useful, but it's good to be aware of that possibility, because once in a while you stumble upon a problem like the one in this thread, and they can provide an elegant solution. Did you know that pointers to data members (as well as to member functions) can also serve as template arguments? Not that it's useful in this particular case, but it's a neat trick.

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

Yeah, the C++11 feature I used (the auto keyword) was just to save space and keep the example cleaner. It's not needed of course.

myk45 commented: agreed +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

<off topic>

BTW, what do those tags (<off topic>) do? Are they just indicators?

Not familiar with HTML or similar languages? Anyone (or any geek) familiar with HTML-like syntax will automatically recognize a structure like <foo> ... </foo> as meaning "start of a block of 'foo', containing ..., and then it ends". In this case, it means a block containing an off topic discussion (as, for example, LastMitch asking you some off-topic question / taunt in the middle of a forum). The system on Daniweb doesn't parse this block and never has, but it is a safe bet that the readers and their geeky minds will parse it correctly.

</off topic>

You should watch this movie called:

Dead Poets Society

I remember seeing that movie some years back, not bad, I thought it was touching but also very cliché. The performance of the actors were very good, but that's about all that is memorable about it, IMHO. And I'm not a big fan of movies that are just vessels for actor performances. I've been blessed with a few very inspiring teachers in my years in school, including an English literature teacher, so the cheap, dramatized, hollywood version of it wasn't very memorable to me.

I find that Scent of a Woman was a much better movie, and did a far better job at conveying its messages, and with impeccable acting too.

Reverend Jim commented: Hoo-ah! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

First, you can use the standard function std::unique (from <algorithm> header) to remove any consecutive spaces by using this predicate (requires header <locale> for the std::isspace function):

bool isConsecutiveSpace(char a, char b) {
  if(std::isspace(a) && a == b)
    return true;
  return false;
};

// call std::unique as so:
std::string my_string = "     Big   Bob  ";
std::string::iterator it_end = std::unique(my_string.begin(), 
                                           my_string.end(),
                                           isConsecutiveSpace);

Then, it is just a matter of removing the first and last characters, if any are spaces too. As in:

std::string::iterator it_beg = my_string.begin();
if(std::isspace(*it_beg))
  ++it_beg;

if((it_end != it_beg) && std::isspace(*(it_end - 1)))
  --it_end;

std::string result(it_beg, it_end);  // copy into the result string.
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Let me demonstrate why all your trivial examples and tests are flawed due to their simplicity. I created the following C example code:

int just_if(int value) {
  int result = 0;
  if(value == 1)
    result = 2;
  if(value == 2)
    result = 4;
  return result * result;
};

int else_if(int value) {
  int result = 0;
  if(value == 1)
    result = 2;
  else if(value == 2)
    result = 4;
  return result * result;
};

int main() {
  return just_if(1) + else_if(2);
};

which I then compiled to obtain the assembly listings for it. Here is how the "just_if" function looks like:

_Z7just_ifi:
.LFB0:
    cmpl    $1, %edi      // compare 'value' to 1
    movl    $4, %eax      // put value of 4 in 'result' (eax)
    je  .L2               // if comparison was true, jump to L2 (just returns)
    xorb    %al, %al      // set 'result' to zero (using bitwise-xor)
    movl    $16, %edx     // put value of 16 in edx
    cmpl    $2, %edi      // compare 'value' to 2
    cmove   %edx, %eax    // if comparison was true, set 'result' to edx (16)
.L2:
    rep
    ret                   // return

And here is the else_if function:

_Z7else_ifi:
.LFB1:
    cmpl    $1, %edi      // compare 'value' to 1
    je  .L9               // if comparison was true, jump to L9
    xorl    %eax, %eax    // set 'result' to zero (using bitwise-xor)
    movl    $16, %edx     // put value of 16 in edx
    cmpl    $2, %edi      // compare 'value' to 2
    cmove   %edx, %eax    // if comparison was true, set 'result' to …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Cygwin is basically what you want. It is exactly that, a unix-like terminal for Windows. It isn't perfect (but nearly so), and might give you a bit of trouble here and there, mostly if you didn't install the packages (in the manual install configurations) that you needed (and, as a beginner, you might not know what you need, so it's a bit of a catch 22). Cygwin is like a Linux-in-a-box program with a very rich set of packages that you can install (using their "setup.exe" program), almost as rich as some basic Linux distributions. With those packages, you can basically get just about every unix tool (including "bash", and much more), or more precisely, the GNU toolset (GNU implementations of classic Unix tools and more, as in "GNU/Linux" which means GNU-toolset + Linux-kernel, well, cygwin just replaces the "Linux-kernel" with "Windows-wrapped-in-a-POSIX-API"). Remember, the Unix "style" is that the overall system is composed of thousands of small programs (tools) each with a very specific task.

Anyway, if you had an error saying that "bin/bash" didn't exist, try checking the list of installed packages and make sure all "bash" related packages are installed ("bash" is not one of the default/minimal-install packages). In general, a package-rich install of cygwin should be able to meet all your unix shell scripting needs and much more.

Another option is, of course, to get Linux either in a virtual box (VirtualBox or VMWare), or as a dual-boot (a bit more …

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

You could just use a pointer to a data member of the class held by the upper-level list. In other words, you can use this:

template <typename TopContainer, typename TopElement, typename BottomContainer>
void genericFoo(const TopContainer& topList, BottomContainer TopElement::* bottomList) {
  for (auto it = topList.begin(); it != topList.end(); ++it) {
    // ...
    const BottomContainer& list2 = (*it).*bottomList;
    for (auto it2 = list2.begin(); it2 != list2.end(); ++it2) {
       // do some stuff
    }
  }
};

Then, call it like this:

int main() {

  genericFoo(listOfItems1, &listOfItems1::value_type::listOfToys);
  genericFoo(listOfItems2, &listOfItems2::value_type::listOfApples);

  // or:
  genericFoo(listOfItems1, &Item1Type::listOfToys);
  genericFoo(listOfItems2, &Item2Type::listOfApples);

};

Enjoy!

myk45 commented: thanks! +5
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Well, I looked at spoj, and they do have different versions available for most of the other languages too. For C++, they explicitly say (g++ 4.3.2) and (g++ 4.0.0-8) which are the GCC C++ compiler versions 4.3.2 and 4.0.0. These are both fairly ancient compilers. If you look at GCC version history, you'll see that 4.3.2 dates back to August 2008, and version 4.0.0 dates back to April 2005. I don't know why they would single out these two particular versions, but my guess is this. The 2005 version states, in the change logs, that only experimental support for TR1 is provided, which hints at the fact that this compiler is probably fully compliant to the C++98 standard but didn't yet include much of the ammendments / additions of C++03 standard (from 2003). The 2008 version probably has complete support for C++03 and TR1 libraries.

Now, why would there be a choice? Wouldn't everyone just want to use the latest version they provide? Well, if you want to make sure that your code is compilable even on an old compiler that supports on C++98 features, then you might want to use that older compiler. Very often, installing an ancient compiler on your own computer can be a real hassle, so an online utility might be a good little tool for checking small things.

You have to understand that programming languages are constantly evolving. Languages like C and C++ are extremely highly used throughout the world, and thus, they are governed …

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

Hi Glen, and welcome to Daniweb!

I am Canadian, and my last name is also Persson. What are the odds, eh? I'm from Quebec, i.e., french-canadian, so I'm used to getting that name messed up all the time, either mistaken for "Pearson" (common english-canadian last name) or for "personne" which means "nobody" in French (when I say: "Hi, my name is Mike Nobody." I get the weirdest faces).

I'm guessing you must have some Swedish ancestry? My father's Swedish, and I have lived there for a while myself.

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

Forum Linguistics 101:

What does OP stand for in OP Kudos:?

(a) Operating Peethan
(b) Obnoxious Pre-madonna
(c) Overflowing Pie-hole
(d) Original Poster

Which one of these multiple choices is correct?

LastMitch commented: Letter d. Thanks ! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

I think you've just agreed with me about the lack of morals in Hollywood.

I think you might have misunderstood me. You made the point that Hollywood lost its morality when they introduced more violence, cursing and sex in their main-stream movies. I refuted that by making the point that Hollywood never really had any morality to begin with, and the violence, cursing and sex doesn't change anything, it's just the latest "working recipe". Hollywood is in fact amoral, in other words, they never cared to produce films that convey any kind of good morals, they have always been only interested in selling products by sticking to recipes that work. So, on that level, we do agree that Hollywood productions lack morality.

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

Bullshit! I don't have to watch two or more people having sex together to know about the problems of sex. I don't have to listen to commedians using the F word whenever it suits him to know about ghetto problems. I don't have to watch one person cutting off another person's fingers to know about drug deals. Hollywood puts all these things in movies purely for profic, just for the $$$.

What you are describing are extremely insipid movies that are being juiced up with bits of sex, cursing and violence, for profit motives. That is exactly what I call Hollywood's wishy-washy attitude. It's easier for them to find a stupid boring script with no meaningful themes addressed in any meaningful or interesting way, and then juice it up. My point is, the problem is not so much the sex, cursing and violence, because these things are just the by-product of a complete lack of imagination, creativity, and critical thinking from the Hollywood crowd. And it is that which I am more afraid of, because it is a lot more dangerous to go on about your life with too few sources (of inspiration) that challenge you and develop your critical thinking, than it is to "be scarred for life" (sarcastic) by a few explicit scenes or some bad language.

Notice also that there are examples at the other end too. Take, for example, the Hollywood version of "The Girl with the Dragon Tattoo". They took a book that …

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

Ok, below is the basic logic, illustrated. I will mark the start pointer with "s", the end pointer with "e", the cursor pointer with "c" and the pointer to the end of the gap with "g". All characters marked as "X" are currently part of the gap (which is only logical, of course, as the actual values of the memory in the gap is just whatever was there before).

So, starting with an empty buffer of length 8:

XXXXXXXX
s       e
c       g

Notice how g == e and s == c at that point, so, the gap fills the entire buffer (capacity == 8, size == 0).

If the user enters the characters "Hi my", you get:

Hi myXXX
s       e
     c  g

Notice how the cursor pointer "c" always points to the place where a new character can be inserted. In other words, every inserted character is written to that place, and then the cursor pointer is incremented, effectively shrinking the gap.

Now, if the user realizes that there needs to be a comma between "Hi" and "my", he moves the cursor back to right after the word "Hi", in which case, a copy occurs which sends a few characters to the end of the buffer, and you get this:

HiXXX my
s       e
  c  g

Notice how the end-of-gap pointer has been moved back as valid characters were copied to the end of the buffer.

So, the user enters a comma:

L7Sqr commented: Very nice explanation and illustration +8
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

All I did is look-up the file "PdfContentsGraph.h" and ended up on this page. Then, I noticed the following line near the top of the header file:

#if defined(PODOFO_HAVE_BOOST)

And then, I wrote the post suggesting to add #define PODOFO_HAVE_BOOST. There's nothing magical about it. Are you saying that you spent "whole days and nights" trying to solve this problem about a class declared in the header file "PdfContentsGraph.h", and it never occurred to you to have a look at the code in that header file? That should have been the first place to look.

So, because PdfContentsGraph (this mini program) was built as part of the whole build process of PODOFO, the PODOFO_HAVE_BOOST macro is in the CmakeLists text file which is probably why it doesn't need it at the top of 'main' for the PdfContentsGraph program.

That makes sense. Another way is to just add PODOFO_HAVE_BOOST as a define in your own building options (in CodeBlocks or whatever else). Or, in command-line, you add -DPODOFO_HAVE_BOOST to the compilation command.

Why would I need to tell PODOFO that I have_boost when I don't do this for all the other dependencies for podofo such as zlib, libpng, libjpeg etc?

It's not unusual to have to do this kind of thing when there are optional dependencies (or dependencies that once were optional). Some libraries even do that for required dependencies too.

Is it because Boost is an external library and not a …

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

Try telling PoDoFo that you have the boost libraries. Add this line to the very start of your code (before including the podofo headers):

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

Some time ago, a colleague happened to ask me if I was active on any online forums. I told him I was a mod on Daniweb. He said: "Daniweb? Never heard of it." So, I popped up a browser on the Daniweb page, and he said: "Oh yeah, the purple forum."

I think it would be kind of impossible to ever change that color at this point. And even if it was possible, I do like the purple color scheme a lot. I'm actually surprised that it isn't more common. So, I guess you can file me under the "keep it purple" camp.

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

she calls the sophmores her pet peeve

So your teacher calls her students an annoyance? Sounds a bit self-defeating to me.

Living in a busy city where I walk everywhere I go, my pet peeve is all those people who just shouldn't be walking in a busy city. You know: those who walk slow and unpredictably drift from side to side so that you can't walk pass them without busting a few dancing moves; those who's field of vision is limited to the few inches of their cell-phone's screen, and inevitably bump into people or into things; those who don't understand that they should stick to the right side (right as in "not left") when crossing people coming the other way; etc. etc.

People who use "I" instead of "me" thinking that it makes them sound educated and proper

@Rev: You must hate the expression "Me, Myself and I". I totally agree with yourself.

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

i tend to watch the games that have a brawl involved... is that normal?

Not so much anymore (stricter rules, and more suspensions, as opposed to just having a penalty or being sent to the locker-room). Unless you are watching some semi-professional leagues. Our local semi-professional league (Ligue de Hockey Junior Majeur du Québec, or LHJMQ) is notorious for being just a pretext to have boxing matches on the ice. And I'm sure many local / provincial leagues in Canada are the same. They literally have some players designated to do the fighting (to fight the designated players from the other team), while the others (normal players who just want to play at this semi-professional level) fill the time between the brawls by playing some hockey. People even take bets on the different fights that we all know are inevitable in any given game, kinda like unlicensed boxing matches. Basically, it's a spectacle that combines hockey, boxing and freezing cold wooden seats... fun for the whole family.. ;)

But, of course, hockey is supposed to be rough around the edges ;). But as long as players stick to the rules (legal tackles, e.g., with the shoulder or hip), and aren't too vicious, it's a fun game, but as I said, I'm not a huge fan. I find it too slow, and not inventive enough. On ice, I would watch a Bandy match any time over a hockey match (Bandy basically takes the rules of soccer (football) …

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

-- Hint: I fixed your formatting. Errors are easier to spot that way. You should develop the habit of doing so yourself in the future. --

My guess is that error comes from forgetting to put the default: statement (or case 3:) between line 118 and 119. Basically, if the "enemy" in not 1 or 2, then the variables (ENatk, ENhull, ENengine, ENwepsys) remain uninitialized, which explains the weird values you get afterwards (which comes from line 128 where ENatk might be uninitialized and cause "damage" to be some very weird / large number).

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

Did you make sure the include the header required for the class PdfContentsGraph? Which is:

#include "PdfContentsGraph.h"

using namespace PoDoFo;  // <-- this is needed too, otherwise you have to use it as 'PoDoFo::PdfContentsGraph'.

The error message is exactly what you get when you forget to include the right header or specify / use the namespace in which the class is. Note that the "expected ';'" part is meaningless, it's just a result of the compiler being a bit confused after it could not recognize the class given in the line of code.

Also, I hope that you realized that this particular example (from PoDoFo) requires you to also download the PdfContentsGraph.h header and its source, as seen in the bottom of this page.

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

“Never. Never ask for what ought to be offered.”
― Daniel Woodrell

Would you guys recommend me for a mod for Daniweb????

Be patient my friend. When I became a mod, I had about 4 times your post count, had been around for about 2 years, had about 100 times your reputation points and above 95% post-quality. You are on the right track, and we have certainly appreciated your contributions, and hope you will keep it up. But I couldn't say you have reached the point of being considered a candidate for promotion to mod status just yet.

I don't quite understand the strength of your desire to be a moderate. After all, all it means is that here and there you resolve those "flag bad post" issues, plus the occasional posts where you put your moderator hat on to moderate on a thread (or remind people of the rules), and the extra "powers" are few, and not to be abused anyways. And the "respect" you get is something that comes for the quality of your posts / contributions, the mod status has little to do with that.

pritaeas commented: Well put. +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

It might help you to know that "sorting using priority queue" is pretty much a synonym for an algorithm called Heap Sort. A priority queue is almost invariably implemented as a heap data structure. And once you have the elements arranged in a heap structure, it is a simple matter to construct the sorted array from it.

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

how do you make your cool or stress free in exams days ?

Humm.. this might sound boring but... How about being well prepared? For the most part, I made sure to sustain a genuine interest in the course material during the term (which just requires an open mind and general curiosity, both pre-requisites to learning). That compelled me to integrate the material as well as to seek to get a good grasp of it as the term progresses. I went to class, did the assignments / exercises (and did them myself), and took notes. When the exam came, I usually studied a few hours the days before the exam (maybe up to 10 hours in the worst cases). On the exam day, if you are confident in your grasp of the course material, and in your ability to solve the problems given, then there is no "bad stress", just the good old adrenaline rush of having to deliver it in time, which is generally helpful. So, the key is confidence, which is built only by working towards being prepared, which is something that you can't do at the last minute.

Of course, this doesn't really apply to "learn-by-heart" courses, only to engineering-style courses where all that matters is your ability to solve problems, and this is partly why I went to engineering school in the first place.

There have been a few exceptions for me, and in most cases, it was a matter of not being prepared, …

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

I understand that iostream.h is outdated and Microsoft Visual Studio has iostream.

The headers like <iostream.h> are pre-standard (from before C++ was standardized), so it dates back to the 90s or earlier. Most compilers probably still support it for legacy reasons, but they don't have to, and some don't.

However, When I remove the ".h" the setf, ios, etc, line 6 has multiple errors.

This is because of namespaces. The old ".h" version of the I/O stream library pre-dates the introduction of namespaces into the C++ language. Since standardization in the 90s, all components (classes, constants and functions) are required to be within the std namespace, before that, they were in the global namespace.

Also, these functions you refer to, like "setf", "setw" or "setprecision", are technically obtained from the standard header <iomanip>, not <iostream> (although on many compilers, including <iostream> also includes <iomanip>).

But, what does that code mean?
What does namespace actually mean? What does it do?

A namespace is, as its name implies, a space for names. The idea is simple. If you have all these standard libraries, plus your own code, plus the entirety of the codes and libraries that you could grab from the internet, it is pretty much inevitable that there would be name conflicts between them (e.g., two separate libraries choosing to use the same name for a component that they provide). In the old days (i.e., in older languages that don't have namespaces), people would …

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

build-esential was already installed. I reinstalled it but still not work.

Make sure that you purge it before reinstalling:

$ sudo apt-get remove --purge build-essential
$ sudo apt-get install build-essential

Other than that, your problem is a real mystery to me. You might have a better chance on a Linux Mint forum or bug reporting system.

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

See this C++ FAQLite entry.

Long story short, the definition (implementation) of all templates must be visible in all translation units that use it. Best way to achieve that is to put it in the header file. You can still separate the declaration and definition (but still both in the header file), if you want a cleaner set of declarations.

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

Being a geek and all, here are some command-lines to fix the World's problems:

The anarchists would say:

$ sudo reboot

The conservatives would say:

> chkdsk /r

The progressives would say:

$ sudo apt-get update

The neo-cons would say:

$ srm -R any_country@middle.east:/*

Christian fundamentalists would say:

> FORMAT C: /FS:Jesus

And the Muslim fundamentalists would say:

> FORMAT C: /FS:Allah
Reverend Jim commented: Great! +0
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

What is the purpose of static member functions in a class?

Well, others have already pointed out one kind of purpose for static member functions. But there are many others too. In other words, there are many "tricks" that rely on a static member function(s). So, it's pretty hard to pinpoint a single purpose for them. Here is a list of the purposes that I can think of off the top of my head:

  • Access and manipulate some static data members (i.e., values globally associated to the class, not the individual instances, like instance counts, global parameters, etc.).
  • Write factory functions (or "named constructors") that allow you to create objects of the given class through a static member function (which has access to (private) constructors). This can be useful for many reasons, like:

    • Allocating the new objects through some alternate scheme (e.g., like a memory pool).
    • Enforcing the use of a smart-pointer to the objects (e.g., std::unique_ptr or std::shared_ptr) by making it impossible to create objects outside of the static "factory" functions.
    • Registering some information about created objects in some global repository / database (e.g., a garbage collection scheme, or just general system-wide lookups of objects in existence).
    • Enforcing a "single instance" rule in what is called a Singleton pattern.
    • Simply providing many alternative construction methods which have distinct names, promoting clarity as to what this particular construction method does (i.e., instead of relying on overloading of the constructors, which can be ambiguous and unclear as to …
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Refer to the PoDoFo mailing list archive. Specifically, this thread which talks about your exact problem. For specific problems about building PoDoFo, they are probably better equipped to help you.

I actually just checked out the source for PoDoFo and built the library. There were a few annoying hurdles, and the build is very dirty (full of warnings), but successful. It seems that the main problem is that they use a rather misconstruded cmake script for the build. They provide a number of modules (in ./cmake/modules) to find some of the external dependencies. However, these are outdated and buggy, so it's better to use the modules installed with cmake for those external dependencies that have one (you can do so by simply renaming the Find*.cmake file in question to something else that won't be picked up by cmake). On top of that, there is a bug in their top-level CMakeLists.txt at Line 30, they override the CMAKE_MODULE_PATH which is a terrible thing to do, the line should be replaced by either:

SET(CMAKE_MODULE_PATH "${CMAKE_MODULE_PATH}" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

or

SET(CMAKE_MODULE_PATH "${CMAKE_ROOT}/Modules" "${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules")

Also, they use the old-style variable names like *_INCLUDE_DIR, as opposed to the new style *_INCLUDE_DIRS (e.g., they use ${FREETYPE_INCLUDE_DIR} instead of ${FREETYPE_INCLUDE_DIRS}), which is pretty outdated, too outdated for many of the more modern package-finding modules to provide them as backward compatibility (that may be why they provide their own outdated modules).

So, again, direct your build problems to the maintainers of that library, and …

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

The problem is probably with the interaction of non-const references and the function binding library, they don't always play nice together (although they should, IMO). Try using a reference-wrapper. Something like this:

threads.push_back(thread (run_es_pval, start,  end, rankedSize, std::ref(datasetNames), std::ref(datasets), std::ref(dicoArray), es_threshold));
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

Just to add a remark, the more typical (hassle-free and safe) implementation of a singleton class is as follows:

// in header:

class Singleton 
{
    private: 
        Singleton() {
          // ...
        }
        Singleton(const Singleton&); // no implementation. non-copyable
        Singleton& operator=(const Singleton&); // no implementation. non-copyable
    public:
        static Singleton& getInstance();  // get instance by reference
        Animal *method(string something);
};

// in cpp file:

Singleton& Singleton::getInstance() {
    static Singleton inst; // just a single static instance of the Singleton object.
    return inst;
}
//...
mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster

As deceptikon said, mixing new/delete and new[]/delete[] is undefined behavior because there is no requirement for the implementation (compiler + standard libraries) to use the same underlying mechanism for both variants. That's why it is undefined behavior, which just means that there is nothing in the C++ standard that defines the behavior that such code should produce, which means, you can't reasonably expect anything predictable out of that code. In addition, you can easily overload those operators and create your own allocation mechanisms that would make the mixing of the two variants result in a crash (or other corruption).

I thought delete[] just loops through everything and calls delete?

That's not true at all. The main difference between delete and delete[] is that the former expects a single object to exist at the given address, and thus, calls the destructor on that object alone. While, on the other hand, the delete[] operator expects an array of objects to exist starting from the given address, has some kind of mechanism to figure out how many there are (probably something like asking the heap about the size of that memory block and dividing that by the size of the class (or type)), and then, it calls the destructor on each object individually. Only after the calls to the destructors, the memory gets deallocated ("deleted"). Most implementations would probably implement the memory deallocation in exactly the same way for both the delete and delete[] operators, but again, that's not a guarantee, …

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

As I told you in this other thread, the CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH are environment variables, and they contain a list of paths that cmake ought to use in order to find the libraries on your system. You should definitely not set them as command-line argument to cmake. What is the output if you simply run this command:

cmake ..

In other words, without any options at all. All the options that you have put in the command line as per your last post, were wrong. You shouldn't define individual tokens like ZLIB_INCLUDE_DIR in the command-line. All your libraries seem to be installed on the C:\ directory, there should be not problem for cmake to find them automatically, as long as you leave the variables CMAKE_INCLUDE_PATH and CMAKE_LIBRARY_PATH intact, or make sure that C:\ is listed in them, when you look at their values in the environment variable listing of your computer.

mike_2000_17 2,669 21st Century Viking Team Colleague Featured Poster
  1. Make sure that libpng and zlib are installed on your computer.
  2. Make sure that FindPNG.cmake module is installed on your computer (should be by the default cmake install). To find it, make a file search for the file name "FindPNG.cmake", and you should find it in CMake's "Modules" directory.
  3. Make a small test to make sure it is found correctly, i.e., try this CMakeLists.txt file:

    cmake_minimum_required (VERSION 2.6)
    project(PNGTest)

    find_package(PNG REQUIRED)

    message(STATUS "LibPNG package was found with include dir: '${PNG_INCLUDE_DIRS}'")

  4. Run a clean cmake configuration on the code that you originally wanted to compile.

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

In the function you just posted, you forgot to handle the misalignment at the end of the pixel rows. This should work:

void JNIData::FlipBytes(void*& Result) {
   unsigned long Chunk = (Bpp > 24 ? width * 4 : width * 3 + width % 4);
   unsigned char* Destination = static_cast<unsigned char*>(Result);

   unsigned char* Source = &BufferPixels[0] + Chunk * (height - 1);

   while(Source != &BufferPixels[0]) {
      std::memcpy(Destination, Source, Chunk);
      Destination += Chunk;
      Source -= Chunk;
   }
}

As for the earlier version (in original post), I would just forget about it. The monkey business with this line:

int Offset = TopDown ? (height - 1 - I) * width + J : I * width + J;

looks very suspicious to me. If anything, you should probably use a strategy similar to that of the other version, i.e., go backwards in the source image, and forward in the destination image.

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

I think your question is just too broad and too narrow at the same time. I say too broad because one could interpret it as just "I want to learn about software engineering". And I say too narrow because you make references to the specific problem of linking, using and building external libraries, which is a very practical issue (as opposed to a "computer science" issue). I personally don't really know what to make of it.

Learning to use external libraries and understanding the compiling-linking process for a given language / platform / build-system is something that you just pick up as part of the process of learning to program in those tools. There are some guidelines for sure, but by and large this is just practical know-how and common sense. My advice on that side of it would be to just look at how certain projects are setup and what their guidelines are. Many open-source projects (the good and large ones, at least) have a set of guidelines and procedures about the overall organizational issues, code reviews, unit-test policies, release schedules, version control, etc. Try reading some of them a bit, just look for them in the "developers -> guidelines" section of the project's webpage. I don't know of any books on this topic specifically. Some general C++ books will talk about some of these issues a bit, like C++ Coding Standards or Exceptional C++.

Other than that, I can't really recommend anything more. In …

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

The same as its English meaning: a lump of anything.

As far as I know, the word has no special meaning in C++, and I would know if there was. It just means a piece of memory or code or anything.

Do you have a specific context in which you read or heard the word being used?

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

What would you say is the steepest part? Generally speaking, that is.

For the complete beginner, the first major hurdle is just understanding how programming works, i.e., basic procedural programming concepts like variables, arithmetic, pointers, arrays, loops, algorithms, and functions. But that's not a problem for someone with some experience in any other language. Then, the second hurdle is dealing with the construction of a software architecture, which includes object-oriented programming, polymorphism, and resource management strategies. Some languages like Java or Python kind of skip that hurdle by making OOP a requirement by design of the language, broad-brushing everything as polymorphic, and handling memory management automatically. In C++, you have to learn to use these concepts at the right places (mix different paradigms) and be able to implement them correctly, and while you are still learning to do those things, there can be a lot of suffering in the form of memory corruption bugs and other nasty things. But once you have a handle on that, and you are somewhat familiar with basic uses of templates, and you are good at employing the C++ standard libraries (especially the STL), which all go hand-in-hand pretty much, then everything is as easy, if not more, than in any other language, including doing GUI programming.

Those who can't get past the first hurdle are not made to be programmers. And those who can't get past the second hurdle will probably never become expert programmers, but might be proficient programmers (good enough …

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

A few hundred bytes is the least I can expect to deal with.

By a few hundred bytes, I didn't mean that the entire document is only a few hundred bytes, but I meant that the chunks that make up your "piece table" (i.e., the pieces) are a few hundred bytes each, at least. This is basically to the point of how fine-grained your pieces are. On the one extreme, you can make a "piece" to represent each individual addition / subtraction of text, which would probably average at a few dozen characters each (e.g., like what would typically show up in different colors when you turn "track changes" on in MS Word). On the other extreme, you would store the entire text in one continuous (gap) buffer. Neither of these solutions would be good when working with a large document. The optimum would certainly lie in the middle somewhere, i.e., as a sequence of (gap) buffer segments which are maintained to a reasonable size (merged when shrinking too small, split when expanding too big), which I would roughly estimate to be around 1000 or 2000 characters on average.

If it turns out to be piece-table based, then that would be the icing on the cake.

I doubt that. The LaTeX format, which I encourage you to learn / play-with, is essentially in the form of a tree. This is also similar to the way HTML works. And I think that the docx format for MS …

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

I don't know much specifically about a word processor, but I would certainly expect all of them to be using some form of a MVC pattern (Model-View-Control). I would also expect that all the word processor use some form of a markup language to represent the actual text along with all the meta-data (formatting, images, labels, cross-references, etc.), that's the "Model". This markup'ed text would certainly be stored internally to the word processor in the form of a graph, not just a simple buffer of text characters. Creating a complete specification for such a markup language, even for simple documents, is quite an endeavour. I would recommend you pick one that already exists and base your graph structure on that. Then, the "control" part would be merely about creating functions to do graph surgery, which has its challenges, but at least, it is incremental and modular in nature.

I also don't like typical word documents like MS Word or LibreOffice, and for that reason, I, like many others in academic fields, use LaTeX instead. LaTeX is usually written directly in LaTeX commands, as opposed to using some word processor. I would highly suggest that you base your markup language on LaTeX (or a subset of it), that's gonna take care of a significant part of this project. On that front, you might want to take a look at LyX, which is a simple word processor based on LaTeX.

By the way, I don't buy your arguments about using …