c++

Static code analysis tool for detecting uncaught exceptions in a C++ code before compilation?

I'm looking for such a tool to be able to check fast if I catch all the exceptions I generate myself. Thanks! ...

Sub Language C#

Hi All I was just wondering, is it at all possible to create sort of like a "Sub-language" in C# OR C++? or would a better term be "Extension"? And can somebody please provide links/resources? Much appreciated! :) thanks jason ...

Throwing a new exception while throwing an old exception

If a destructor throws in C++ during stack unwinding caused by an exception, the program terminates. (That's why destructors should never throw in C++.) Example: struct Foo { ~Foo() { throw 2; // whoops, already throwing 1 at this point, let's terminate! } }; int main() { Foo foo; throw 1; } terminate cal...

Adapting Map Iterators Using STL/Boost/Lambdas

Consider the following non-working code: typedef map<int, unsigned> mymap; mymap m; for( int i = 1; i < 5; ++i ) m[i] = i; // 'remove' all elements from map where .second < 3 remove_if(m.begin(), m.end(), bind2nd(less<int>(), 3)); I'm trying to remove elements from this map where .second < 3. This obviously isn't written correctl...

Remove never-run call to templated function, get allocation error on run-time

I have a piece of templated code that is never run, but is compiled. When I remove it, another part of my program breaks. First off, I'm a bit at a loss as to how to ask this question. So I'm going to try throwing lots of information at the problem. Ok, so, I went to completely redesign my test project for my experimental core librar...

why don't STL ifstream and ofstream classes take std::string as filenames?

This is a complaint about STL. Why do they take filename arguments as (char *) and not as std::string? This seems to make no sense. There are two other questions on this topic: How to open unicode filenames with STL Windows Codepage interactions with C++ The issue is that I have a lot of code that looks like this: std::ofst...

Weird behaviour with vector::erase and std::remove_if with end range different from vector.end()

Hi, I need to remove elements from the middle of a std::vector. So I tried: struct IsEven { bool operator()(int ele) { return ele % 2 == 0; } }; int elements[] = {1, 2, 3, 4, 5, 6}; std::vector<int> ints(elements, elements+6); std::vector<int>::iterator it = std::remove_if(ints.begin() + 2, ints.begin...

complex arguments for function

My task is to create function funCall taking four arguments : pointer for 2d array of ints that stores pairs of numbers variable int maintaining number of numbers in 2d array pointer for table of pointers to functions int variable storing info about number of pointers to functions I was thinking about something like this : typedef i...

dynamically created arrays

My task consists of two parts. First I have to create globbal char array of 100 elements, and insert some text to it using cin. Afterwards calculate amount of chars, and create dedicated array with the length of the inputted text. I was thinking about following solution : char[100]inputData; int main() { cin >> inputData >> endl;...

C++ sort method

I want to sort a vector using std::sort, but my sort method is a static method of a class, and I want to call std::sort outside it, but it seems to be trouble doing it this way. On the class: static int CompareIt(void *sol1, void *sol2) { ... } std::sort call: sort(distanceList.at(q).begin(), distanceList.at(q).end(), &...

How can I set the line style of a specific cell in a QTableView?

I am working with a QT GUI. I am implementing a simple hex edit control using a QTableView. My initial idea is to use a table with seventeen columns. Each row of the table will have 16 hex bytes and then an ASCII representation of that data in the seventeenth column. Ideally, I would like to edit/set the style of the seventeenth column t...

Extremely CPU Intensive Alarm Clock

EDIT: I would like to thank you all for the swift replies ^^ Sleep() works as intended and my CPU is not being viciously devoured by this program anymore! I will keep this question as is, but to let everybody know that the CPU problem has been answered expediently and professionally :D As an aside to the aside, I'll certainly make sure...

Why isn't the copy constructor elided here?

(I'm using gcc with -O2.) This seems like a straightforward opportunity to elide the copy constructor, since there are no side-effects to accessing the value of a field in a bar's copy of a foo; but the copy constructor is called, since I get the output meep meep!. #include <iostream> struct foo { foo(): a(5) { } foo(const foo& f)...

What's your convention for typedef'ing shared_ptr?

I'm flip-flopping between naming conventions for typedef'ing the boost::shared_ptr template. For example: typedef boost::shared_ptr<Foo> FooPtr; Before settling on a convention, I'd like to see what others use. What is your convention? EDIT: To those nesting the typedef inside Foo, doesn't it bother you that Foo is now "aware" of ho...

C++ choose function by return type.

I realize standard C++ only picks functions by argument type, not return type. I.e I can do something like: void func(int); void func(double); but not double func(); int func(); Where in the former, it's clear, in the latter, it's ambigious. Are there any extensions that lets me tell C++ to pick which function to use also by return...

C++ Vector of vectors

I have a class header file called Grid.h that contains the following 2 private data object: vector<int> column; vector<vector<int>> row; And a public method whose prototype in Grid.h is such: int getElement (unsigned int& col, unsigned int& row); The definition of above mentioned function is defined as such in Grid.cpp: int getEle...

Having an issue with overwriting an element of a file correctly (numeric)

This is an ATM style program, but currently it doesn't do exactly what I need it to do... I need to get the current balance, and when money is transferred from either checking or savings, it should add it to checking and subtract it from savings. which is does, but not correctly... Input example -=[ Funds Transfer ]=- -=[ Savings to C...

static arrays defined with unspecified size, empty brackets?

For the C++ code fragment below: class Foo { int a[]; // no error }; int a[]; // error: storage size of 'a' isn't known void bar() { int a[]; // error: storage size of 'a' isn't known } why isn't the member variable causing an error too? and what is the meaning of this member variable? I'm using gcc version 3.4.5 (mingw...

Should '#include' and 'using' statements be repeated in both header and implementation files (C++)?

I'm fairly new to C++, but my understanding is that a #include statement will essentially just dump the contents of the #included file into the location of that statement. This means that if I have a number of '#include' and 'using' statements in my header file, my implementation file can just #include the header file, and the compiler w...

How can I make a proccess in an OnLButtonDown() event happen again and again untill I live the button?

What happen until now is this: Any line happens once, and if I use awhile(1) or while (nFlags == MK_LBUTTON) its working as it should but I get a crash. The other problem, or maybe the same one is the delay if I will be able to do it, maybe using while() with Timer()? I was thinking about Timer() to recall the function with delay but ...