I have been looking into using Boost.Interprocess to create a disk-backed data structure. The examples on Boost Documentation (http://www.boost.org/doc/libs/1_41_0/doc/html/interprocess.html) are all for using shared memory even though they mention that memory mapped files can also be used. I am wondering whether anyone here has used mem...
I want to create a function that will take a string and an integer as parameters and return a string that contains the string parameter repeated the given number of times.
For example:
std::string MakeDuplicate( const std::string& str, int x )
{
...
}
Calling MakeDuplicate( "abc", 3 ); would return "abcabcabc".
I know I can do t...
Using Visual Studio, it is possible to 'Ignore Specific Library'
(Project Properties > Configuration Properties > Linker > Input > Ignore
Specific Library).
We found this useful in a project. Now we want to build
that project using boost-build (bjam), but we need to reproduce that linker behaviour.
Is there any ignore library feature w...
I'd like to see all the places in my code (C++) which disregard return value of a function. How can I do it - with gcc or static code analysis tool?
Bad code example:
int f(int z) {
return z + (z*2) + z/3 + z*z + 23;
}
int main()
{
int i = 7;
f(i); ///// <<----- here I disregard the return value
return 1;
}
Update:
it ...
Hello, my fellow developers! I hope very much that at least some of you will not get frightened by the amount of text this question contains (I simply did my best to be as descriptive as humanely possible). :)
To those who think I've asked this question to write malware or something. I want to write an application that will allow users ...
I'm trying to implement an algorithm we did in numerical methods class. I have an identical procedure written in Maple and it works fine. I can't understand why it isn't working in C++.
Any help or tips would be appreciated; thanks in advance.
#include "stdafx.h"
#include "math.h"
#include <iostream>
using namespace std;
double absv...
How do I restore the stack trace function name instead of <UNKNOWN>?
Event Type: Error
Event Source: abcd
Event Category: None
Event ID: 16
Date: 1/3/2010
Time: 10:24:10 PM
User: N/A
Computer: CMS01
Description:
Server.exe caused a in module at 2CA001B:77E4BEF7
Buil...
Hi,
I've recently started using boost lambda and thought I'd try and use it in places where it will/should make things easier to read.
I have some code similar to the following
std::vector< X * > v;
for ( int i = 0 ; i < 20 ; ++i )
v.push_back( new X() );
and later on, to delete it...
std::for_each( v.begin(), v.end(), boost::l...
Please refer to rule #41 of C++ Coding Standards or Sutter's Gotw #70, which states that:
Make data members private, except in behaviorless aggregates (C-style structs).
I often would like to to add a simple constructor to these C-style structs, for the sake of convenience. For example:
struct Position
{
Position(double lat=0....
I'm curious about the benefits/detriments of different constant declaration and definition options in C++. For the longest time, I've just been declaring them at the top of the header file before the class definition:
//.h
const int MyConst = 10;
const string MyStrConst = "String";
class MyClass {
...
};
While this pollutes the globa...
First, I want to thank Matt Davis for this post. I know the post was not chosen as the answer to that specific question, but the post was extremely helpful to me. I had a couple small issues to fix (mostly adjusting the filepaths in the code he provided), but I was easily able to create an unmanaged C++ client for a C# WCF service usin...
bool "bar" is by default true, but it should be false, it can not be initiliazied in the constructor. is there a way to init it as false without making it static?
Simplified version of the code:
foo.h
class Foo{
public:
void Foo();
private:
bool bar;
}
foo.c
Foo::Foo()
{
if(bar)
{
doSomethink();
}
}
...
Is it possible to detach a native socket from Boost.ASIO's socket class? If so, how can it be done? I can't seem to find anything obvious in the documentation.
As a quick overview of what I'm trying to accomplish: I have a class that makes a connection and does some negotiation using Boost.ASIO, then passes back a native Windows SOCKET ...
I have an application where part of the inner loop was basically:
double sum = 0;
for (int i = 0; i != N; ++i, ++data, ++x) sum += *data * x;
If x is an unsigned int, then the code takes 3 times as long as with int!
This was part of a larger code-base, but I got it down to the essentials:
#include <iostream> ...
Consider the following:
struct Point {double x; double y;};
double complexComputation(const& Point p1, const Point& p2)
{
// p1 and p2 used frequently in computations
}
Do compilers optimize the pass-by-reference into pass-by-copy to prevent frequent dereferencing? In other words convert complexComputation into this:
double comp...
Do the underlying bits just get "reinterpreted" as a floating point value? Or is there a run-time conversion to produce the nearest floating point value?
Is endianness a factor on any platforms (i.e., endianness of floats differs from ints)?
How do different width types behave (e.g., int to float vs. int to double)?
What does the l...
Hello everyone! I have a QTreeWidget with items in it. The first column contains a unique number. This is set via item->setData(0, 0, unique_number);. The second column contains a checkbox, set via item->setCheckState(1, Qt::Unchecked);. The user can select the items (s)he would like to work with and presses a button. The slot for this b...
Basically, I have a pure virtual class Base, and a concrete class Derived which inherits from Base. I then allocate a piece of memory and treat it as an array of Derived via a simple cast. Then, I populate the array using =. Finally, I loop through the array, trying to call the virtual method GetIndex that is declared in Base and defined...
hi,
I am basically trying to get a user to input a hexadecimal input via
getline into a string as i will do other operations on this. (using c++ .net stuff won't work)
i do not want to break this into chars per say and then go through each char in the string and see if its in range from [0-9] or [Aa-Ff].
Instead, I wanted to know if...
Hello everyone,
Every time i try to read a file form the hard drive and cast the data into a structure, i end up with problems of the data not casting properly. Is there a requirement with the reinterpret_cast() function that requires the number of bytes in a structure be a multiple of 4 bytes? If not, what am I doing wrong? If so, how ...