question_id int64 25 74.7M | answer_id int64 332 74.7M | title stringlengths 20 150 | question stringlengths 23 4.1k | answer stringlengths 20 4.1k |
|---|---|---|---|---|
3,843,373 | 3,843,378 | Binary trees in C++ using references | I wish to implement a binary tree using references instead of using pointers (which is generally what you tend to find in every book and every website on the internet). I tried the following code:
class tree_node {
private:
tree_node& left;
tree_node& right;
data_type data;
public:
void set_left(tree_no... | You can't change the object that a reference refers to1; once you initialize a reference, it always refers to the object with which it was initialized.
You should use pointers. There is nothing wrong with using pointers for this (it's clean using pointers as well because parent nodes own their children, so cleanup and... |
3,843,582 | 3,846,180 | vector template conflicting declaration | I'm trying to implement a function that allows me to make a call like this
// vec5 is a vector of tuples in my case
// some code that to declare and fill vec5
columnViewOfTuple<0>(vec5);
I implemented such function as follows
template<int N>
struct myfunction {
template<typename T, typename R>
std:... | Johannes has explained what is wrong.
This is what you could do.
1) I don't see a need for it to be a struct, hence a free function (do as it suits you better).
2) The type of the nth element can be queried from the tuple with boost::tuples::element (and the type of the tuple can be queried from the container with the ... |
3,843,634 | 3,877,095 | Shouldn't be these warnings with g++ -Wall? | I was just curious if the following code should result in warning or not by g++ compiler:
// Snip #1
bool x = 0;
x++;
// Snip #2
switch (x) {
default:
printf("hi\n");
}
The problem is such statements exist in a legacy code i work upon :-|, I guess there should be some warnings for these?
I have g++-4.4.3c
| Incrementing a bool is a deprecated function, yet it is still valid and achieves the desired result, therefore a warning should not appear, it is just bad practice to do so.
|
3,843,711 | 3,843,743 | Friend classes across different namespaces. Is that possible | I'm having problems trying to use the friend feature of C++. I have these interfaces:
#pragma once
#include "Mesh3D.h"
#include <string>
namespace tools{
namespace sysInput{
class CGeometryManager3D
{
public:
bool loadFromFile(render::CMesh3D& mesh, std::string filename);
... | See if something like this works a bit better (for the moment, I've merged them into a single source file).
#include <string>
namespace tools {
namespace sysInput {
class CGeometryManager3D;
}
}
namespace render {
class CMesh3D
{
public:
friend class tools::sysInput::CGeometryMa... |
3,843,925 | 3,844,043 | C++ inheritance problem | I am trying to implement a leftist tree using heaps as a base class. The following is the contents of heap.h:
template <class T>
class heap {
public:
virtual void init(T*) = 0;
virtual void insert(T*) = 0;
virtual T delete_min() = 0;
};
The following is the contents of leftist.cpp:
#include "heap.h"
temp... | Template functions are treated a little differently from regular functions. The compiler doesn't actually compile the function until you try to use it. If the only place you try to use it is a .cpp where the body of the function is undefined, it assumes it must be compiled somewhere else and makes a reference for the l... |
3,843,983 | 3,843,992 | Change the executable name in Eclipse for C++ | I've created a C++ project in Eclipse and currently it builds an executable called file.exe but I want to change this to "file".
How do I do this?
Thanks.
| You cannot remove the .exe from the filename, because windows uses this to determine the file type, and be removing the .exe, then it will not know that the file is an executable.
|
3,844,010 | 3,844,031 | Convert a double to fixed decimal point in C++ | I have a double variable in C++ and want to print it out to the screen as a fixed decimal point number.
Basically I want to know how to write a function that takes a double and a number of decimal places and prints out the number to that number of decimal places, zero padding if necessary.
For example:
convert(1.235, 2... | Assuming I'm remembering my format strings correctly,
printf("%.*f", (int)precision, (double)number);
|
3,844,374 | 3,844,381 | Test for void pointer in C++ before deleting | I have an array in C++:
Player ** playerArray;
which is initialized in the constructor of the class it is in.
In the destructor I have:
delete playerArray;
except when testing the program through Valgrind it says that there are some calls to delete to a void pointer:
operator delete(void*)
I want to test whether t... | Perhaps you meant delete [] playerArray. You need the [] if the pointer is an array, not a single instance.
|
3,844,570 | 3,844,654 | Function passing arguments in reverse | Here is my function:
void abc(char *def, unsigned int w, unsigned int x, unsigned int y, unsigned int z)
{
printf("val 1 : %d\n", w);
printf("val 2 : %d\n", x);
printf("val 3 : %d\n", y);
printf("val 4 : %d\n", z);
}
and here is where I call this function:
unsigned int exp[4] = { 1, 2, 3, 4 };
unsigned sh... | From standard docs, 5.4
Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions,
and the order in which side effects take place, is unspecified58) Between the previous and next sequence point a
scalar object shall have its stored value modified a... |
3,844,721 | 3,844,759 | Algorithm to generate all permutation by selecting some or all charaters | I need to generate all permutation of a string with selecting some of the elements. Like if my string is "abc" output would be { a,b,c,ab,ba,ac,ca,bc,cb,abc,acb,bac,bca,cab,cba }.
I thought a basic algorithm in which I generate all possible combination of "abc" which are {a,b,c,ab,ac,bc,abc} and then permute all of the... | I don't think you can write much faster program than you have already. The main problem is the output size: it has order of n!*2^n (number of subsets * average number of permutations for one subset), which is already > 10^9 for a string of 10 different characters.
Since STL's next_permutation adds very limited complexi... |
3,845,008 | 3,851,026 | CMake with Visual Studio | I'm using CMake to create a visual studio project as I'm making a cross platform application and library, but I get errors like:
1>c:\program files\microsoft visual studio 10.0\vc\include\wchar.h(109): warning C4820: '_wfinddata64i32_t' : '4' bytes padding added after data member '_wfinddata64i32_t::attrib'
It compil... | For the opengl errors, you need to include windows.h before including gl.h. Hope it helps.
#ifdef WIN32
# include <windows.h>
#endif
#include <GL/gl.h>
|
3,845,019 | 3,845,037 | Is it a bad practice to use the name of a type for a member function or variable? | If the answer is yes, can you tell me why? here is an example:
namespace urx {
struct reserved { };
struct side { urx::reserved reserved() { /*...*/ } };
}
int main() {
urx::side side;
side.reserved();
}
reserved is used for both a type name and a function name.
side is used for both a type name and a... | I don't see why this would be bad. I think I would rather name my member functions consistently with good names than to invent hard to remember artificial names to disambiguate them.
Some coding guidelines are written such that this case cannot happen. By forcing types to start with an upper-case letter and functions ... |
3,845,021 | 3,845,052 | reading a binary file | Is it necessary to use reinterpret_cast< char*> when reading from a binary file. Since I found that a explicit typecast worked as well e.g. (char*), sizeof(int).
| both reinterpret_cast and the C-style explicit cast do exactly the same thing in your context. I prefer reinterpret_cast as it makes the nastiness more explicit when reading the code.
|
3,845,022 | 3,845,180 | Pain free way to call a managed c# function (with no return value) from unmanaged c++? | I have been tasked with maintaining a legacy unmanaged c++ system. I do not have access to the source of the entire system but I do have the source to a number of extension dlls that, when included in the same directory as the core system, will be loaded instead of the built in defaults.
I have used the extensions in ... | I've investigated this topic couple of years ago: I want to use log4net and Npgsql libraries from native code that compiles even withour /clr key.
The main idea behind this technique described by Paul DiLascia in his two remarkable articles:
Managed Code in Visual Studio 2005
Use Our ManWrap Library to Get the Best of ... |
3,845,229 | 3,845,256 | templates value `defValue' cannot appear in a constant- expression | As i understood, template value need to be known in compilation time.
so i write a little example just to see that i get it, but apperantly i didn't.
so i get this:
`defValue' cannot appear in a constant-
expression
can anyone please what is the problem and how it can be fixed?
#include <iostream>
template <class T,T... | C++03 14.3.2
Template non-type arguments
A template-argument for a non-type, non-template template-parameter shall be one of:
— an integral constant-expression of integral or enumeration type; or
— the name of a non-type template-parameter; or
— the address of an object or function with external linkage, ... |
3,845,328 | 3,845,340 | Understanding OOP thinking. Need help with simple text | Reading the book I found the following:
The way of thinking when you model the problem by its single elements its the base of objected oriented programming.
Also when I want to make a game (e.g.), the player is one element, the level is one element? Those are just basic elements which my application logic consists of... | Yes.
Yes.
&
Yes.
the player is one element, the level is one element?
Yes, they should be some class in your program.
It also says the OOP is closer to way humans think - that is beucase we think more in "objects"?
Yes, we think in objective way. for example, when you mean Player, you know that player could score some... |
3,845,353 | 3,845,404 | what will be the default value of an uninitialized boolean value in c++ | Suppose I have a struct called foo_boolean that contains some boolean values:
struct foo_boolean {
bool b1;
bool b2;
};
If I define a variable of type foo_boolean without initializing it, what will the default value of the member variables be? (i.e., true, false, or a random value of the two.)
| It depends on how you create it. If the struct is constructed by default-initialization e.g.
void foo () {
fool_boolen x; // <---
then the values will be undefined (bad things will happen if you read it before setting a value).
On the other hand, if the struct is constructed by value-initialization or zero-initial... |
3,845,366 | 3,845,799 | C++ view Mutex value in watch window | is it possible to view the value of a Mutex or Semaphore in Watch winodw in debug mode?
| If a debugger could see the internal state of a synchronization object then a program could as well. Allowing it to circumvent the API and use the object in a thread-unsafe manner. This is for your own good, but of course an enormous pita when trying to debug threading problems. Good luck.
|
3,845,411 | 3,846,921 | What is fastest algorithm for getting relative to image shapes formed by aeries with relatively same colors on the given image? | Given image is N*M (R,G,B) pixels like:
Algorithm should tall us how to find main image colors like: red and white here.
Aeries with relatively same colors means we search for (R,G,B) (222, 12, 10) giving for example such step (40, 20, 10 ) so that (199, 32, 5) will count like what we are searching for like:
Shape... | Just a warning. You should be carefull with the wording: if you identify the three "main colors" of your image, you may get the following (code in Mahematica):
|
3,845,521 | 3,845,561 | How to forward declare a class under a namespace in c++, such as std::string? |
Possible Duplicates:
C++, removing #include<vector> or #include<string> in class header
Forward declare an STL container?
I want to forward declare std::string, by the way, can I forward declare a struct?
| std::string is a typedef so you cannot just forward declare it. You could look up the exact declaration, forward declare that and define the typedef yourself, but then you'd also have to forward declare char_traits and allocator. So this should might work, although it's not supposed to*:
namespace std
{
template< cla... |
3,845,564 | 3,845,641 | So now struct can have virtual function and support inheritance ? What difference with classes then ? What the true purpose of information hiding? |
Possible Duplicate:
What are the differences between struct and class in C++
http://www.cplusplus.com/reference/std/typeinfo/type_info/
I guess my "teacher" didn't tell me a lot about the differences between struct and classes in C++.
I read in some other question that concerning inheritance, struct are public by de... | As far as the compiler is concerned, there is no difference between struct and class other than the default accessibility. They're just two different keywords for defining the same thing. So, structs can have constructors, destructors, base classes, virtual functions, everything.
As far as programmers are concerned, i... |
3,845,837 | 5,827,849 | Using main menu as toolbar in Qt | I'd like to create a toolbar that contains main menu, just like the standard main menu
at the top of the window.
Is there some fast way to do this in QT ? I know that I can create a toolbar with buttons and context menus :-)
Thx for help.
| You can add any widget to QToolBar using:
QMenuBar *mb = new QMenuBar();
QToolBar::addWidget(mb);
It might be easier to reparent designer's ui->menubar to toolbar.
|
3,845,990 | 3,846,139 | Managing C++ project - file layout, dependencies and version control | I have recently started a new C++ project and I intend to make it cross-platform in time. I haven't had much experience with C++ projects before so the first thing that bothers me is that default Visual Studio file layout setup. I tried reading-up the Net on this subject but the info just seems rare and conflicting, so... | Just keep in mind what happens when you switch to a different build system on another platform.
It won't know what to do with solution/project files, they're specific to Visual Studio. So it doesn't really matter how you structure that. You'll be re-doing it anyway.
Likewise with the temp directory, intermediate files ... |
3,846,296 | 3,846,374 | How to overload the operator++ in two different ways for postfix a++ and prefix ++a? | How to overload the operator++ in two different ways for postfix a++ and prefix ++a?
| Should look like this:
class Number
{
public:
Number& operator++ () // prefix ++
{
// Do work on this. (increment your object here)
return *this;
}
// You want to make the ++ operator work like the standard operators
// The simple way to do this ... |
3,846,317 | 3,907,389 | Packing 32bit floats into 30 bits (c++) | Here are the goals I'm trying to achieve:
I need to pack 32 bit IEEE floats into 30 bits.
I want to do this by decreasing the size of mantissa by 2 bits.
The operation itself should be as fast as possible.
I'm aware that some precision will be lost, and this is acceptable.
It would be an advantage, if this operation w... | I can't select any of the answers as the definite one, because most of them have valid information, but not quite what I was looking for. So I'll just summarize my conclusions.
The method for conversion I've posted in my question's part 1) is clearly wrong by C++ standard, so other methods to extract float's bits shoul... |
3,846,333 | 3,846,446 | C++ Does not name to a type | This might be an easy question, but I cannot figure out why the compiler it's giving me this error. I have two classes. Agent and Environment. WHen I try to add an object of type Agent in my Environment class I get Agent does not name to a type error. I am including Agent.h in my Environment.h class
#ifndef AGENT_H_IN... | Your agent.h includes environment.h. The agent.h file is parsed in order from top to bottom, so when environment.h is parsed, the compiler doesn't know what an Agent is. There appears to be no reason to incude environment.h in agent.h.
|
3,846,565 | 3,846,613 | Returning a type of an object; | Is it possible to return type of an object? For example I would like to have construct like this:
//pseudocode
template<class T>
void f(int value)
{
//depends on type T different action can be taken
}
template<class T>
type getType(T obj)
{
return (type of obj);
}
and then in main:
f<getType(O... | Yes in some sense, but you need to move T into a parameter. This is the conditional trick explored by Eric Niebler and explained here.
template<typename T>
struct id { typedef T type; };
template<typename T>
id<T> make_id(T) { return id<T>(); }
struct get_type {
template<typename T>
operator id<T>() { return id<T... |
3,846,631 | 3,846,750 | C++ vs Python precision | Trying out a problem of finding the first k digits of a num^num I wrote the same program in C++ and Python
C++
long double intpart,num,f_digit,k;
cin>>num>>k;
f_digit= pow(10.0,modf(num*log10(num),&intpart)+k-1);
cout<<f_digit;
Python
(a,b) = modf(num*log10(num))
f_digits = pow(10,b+k-1)
print f_digits
Input
194234... | Decimal is a built in python class that handles floating points correctly (as base 10, not as IEEE 7somethingsomething standard). I don't know if it supports logarithms and all that though.
Edit: It does indeed support logarithms "and all that".
You can set the precision of it as well. Default is 28 places, but it can ... |
3,846,642 | 3,846,747 | How to query HTML with x XPath expression in C++? | I have a webbrowser and I use DocumentComplete to read the current document from the WebBrowser (as IHTMLDocument2).
What's the easiest way to run xpath queries in that html doc? I am looking for something easy to use and lightweight.
I am using Visual Studio C++ 2010.
|
What's the easiest way to run xpath
queries in that html doc? I am looking
for something easy to use and
lightweight.
I am using Visual Studio C++ 2010.
Generally, XPath expressions cannot be evaluated against HTML documents.
However, if the HTML document is also an XHTML document (which is by definition a well... |
3,846,677 | 3,846,697 | How to store a concatenation of ints and characters in a char*? | I have some integers, let's say one two and three. I wish to create a string such as
char* example = "There are " + one + " bottles of water on " +
two + " shelves in room number " + three + "\n".`
This doesn't work in C/C++. How can I store that type of value in a char*?
| C++ isn't VB. But you have numerous options.
stringstream:
#include <sstream>
#include <string>
stringstream ss;
ss<< "There are " << one << " bottles of water on " << two << " shelves in room number " << three;
string s = ss.str();
boost/format:
#include <boost/format.hpp>
#include <string>
string s = (boost::form... |
3,846,980 | 3,847,031 | Why does this go into an infinite loop? | Okay, so I'm trying to create a list of he folders, and sub-folders and their files, but right now it doesn't print anything, and seems to be going into an infinite loop. Any idea why?
//infinate loop start
for(int j = 0; j < (int) dirs[i].folders.size(); j++){
dirs.push_back(Directory(dirs[i].fold... | The first for loop in main, on line 78, keeps adding files to root.files. On line 81,
getfiles(root.dir,root.files);
Adds the files to root.files. The for loops stops when i is bigger than root.files.size(), but because this size is increased in every iteration, it never stops.
for(int i = 0; i < (int) root.folders.s... |
3,847,061 | 3,847,087 | C++, why is array=ptr legal? | Recently i saw this piece of code. Shouldnt this line be a compile error?char arr[4]="Abc";
What happens here? Is arr a pointer? is the char* copied into an array on stack? is this legal in all version of C++ (and what about C?). I tested and seen this works in VS and code pad which i believe uses gcc
-edit- Just for f... | array = ptr is not a legal assignment (if array has an array type and ptr has the corresponding pointer type). In the code you have shown, though, the = introduces an initializer as it is part of a declaration. It is not an assignment.
It is legal to initialize an array of char with a string constant.
|
3,847,074 | 3,847,137 | How can I generate a directory tree from a root folder and all it's sub folders? | okay, so I'm trying to get a directory of folders and sub folders, but it just goes into a infinite loop. What is a better way to create a directory of folders and sub-folders? Cause I really have no idea.
this is my code so far:
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <errno.h>
#inclu... | I think you have to handle symbolic links to directories differently. There could be the source for your endless loop:
Say /tmp/foo is a symbolic link to /tmp, then I think your program will go into endless loop when .==/tmp
|
3,847,107 | 3,847,149 | Resources to learn Networking with C++ | I'm a newcomer to using C++ but have got a general Idea of its syntax and usability. I want to learn how to communicate over networks through C++ programming though but I can't seem to find any tutorials for C++ specifically.
Does anyone know any good resources to learn about networking with C++ or what I should start ... | Given your newness to C++, I would not recommend building directly on the sockets APIs unless you can find no suitable library to use. Boost.Asio will give you a huge head start and expose you to the higher-level abstractions used in network programming.
It's easy when starting out building a sockets-based system to g... |
3,847,508 | 3,847,545 | Handling TCP Streams | Our server is seemingly packet based. It is an adaptation from an old serial based system. It has been added, modified, re-built, etc over the years. Since TCP is a stream protocol and not a packet protocol, sometimes the packets get broken up. The ServerSocket is designed in such a way that when the Client sends data,... | TCP guarantees that the data will arrive in the same order it was sent.
That beeing said, you can just append all the incoming data to a buffer. Then check if your buffer contains one or more packets, and remove them from the buffer, keeping all the remaining data into the buffer for future check.
This, of course, supp... |
3,847,611 | 3,847,630 | C++ std::ifstream in constructor problem | I've got a problem with this code:
#include <fstream>
struct A
{
A(std::ifstream input)
{
//some actions
}
};
int main()
{
std::ifstream input("somefile.xxx");
while (input.good())
{
A(input);
}
return 0;
}
G++ outputs me this:
$ g++ file.cpp
file.cpp: In function... | Two bugs:
ifstream is not copyable (change the constructor parameter to a reference).
A(input); is equivalent to A input;. Thus the compiler tries to call the default constructor. Wrap parens around it (A(input));. Or just give it a name A a(input);.
Also, what's wrong with using a function for this? Only the class's... |
3,847,708 | 3,847,723 | How do you output binary representation of floats? | I am new to programming, I've done web development, but I am currently trying to learn real programming. The question I have is already answered here.
union ufloat {
float f;
unsigned u
};
ufloat u1;
u1.f = 0.3f;
What I don't get is how it works. What does the 0.3 part do? I couldn't find it in my text. And how ... | 0.3 is just a test value. Printing u1.u will not give you the binary representation, but the value of the binary representation interpreted as a base 10 integer. To get the binary value, you have to convert u1.u to binary.
Another way you can do the conversion is by using bitwise operators.
For example:
unsigned x = 11... |
3,847,905 | 3,847,918 | Static members and templates in c++ | Given the code:
#include <iostream>
using namespace std;
template <typename T>
T my_max (const T &t1, const T &t2)
{
static int counter = 0;
counter++;
cout << counter << " ";
return ((t1 > t2) ? t1 : t2);
}
int main()
{
my_max (2,3);
my_max (3.5, 4.3);
my_max (3,2);
my_max ('a','c');
}
... | What happens is that the compiler instantiate the function for every type(used one of course). So, you would have the following "functions" internally:
int my_max (const int &t1, const int &t2)
{
static int counter = 0;
counter++;
cout << counter << " ";
return ((t1 > t2) ? t1 : t2);
}
...
double my_max... |
3,847,916 | 3,847,928 | assignment operator in c++ | let's assume I have some class A and derived from it B:
I want to write operator= for B (let's assume that I have operator= in my A class)
right way to do this:
B& B::operator=(const B& rhs)
{
if(this == &rhs) return *this;
((A&) *this) = rhs; //<-question
//some other options
return *this
}
what is the difference if ... | Your second code would copy just the A part (slicing) of *this into a temporary variable, assign it, and throw it away. Not very helpful.
I would instead write that line as:
A::operator=(rhs);
which makes it very clear that it is invoking the base class version.
Cast-and-assign could be better in a template situation... |
3,848,074 | 3,848,135 | Function pointers and their called parameters | This may be the wrong approach, but as I dig deeper into developing my game engine I have ran into a timing issue.
So lets say I have a set of statements like:
for(int i = 0; i < 400; i++)
{
engine->get2DObject("bullet")->Move(1, 0);
}
The bullet will move, however, on the screen there won't be any animation. It ... | I don't think this is the right direction. After you store 400 moves in a vector of function pointers, you'll still need to pop and perform a move, redraw the screen, and repeat. Isn't it easier just to move(), redraw, and repeat?
I'd say your bullet is warping because it's moving 400 pixels/frame, not because you need... |
3,848,093 | 3,848,103 | Storing NUL characters (ASCII 0) | I've created a program in C++ that prompts the user for a filename and for the requested filesize. The program checks if the requested filesize is bigger than the actual filesize and then adds null characters (the ones with code 0) at the end of the file, until the requested filesize is reached.
I have done it like thi... | Here's an example:
#include <algorithm>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
ofstream fout("pokemon");
char buffer[1000];
std::fill(buffer, buffer + 1000, '\0');
fout.write(buffer, sizeof(char) * 1000);
return 0;
}
|
3,848,239 | 3,849,435 | Trying to group values? | I have some data like this:
1 2
3 4
5 9
2 6
3 7
and am looking for an output like this (group-id and the members of that group):
1: 1 2 6
2: 3 4 7
3: 5 9
First row because 1 is "connected" to 2 and 2 is connected to 6.
Second row because 3 is connected to 4 and 3 is connected to 7
This looked to me like a graph trave... | I've managed O(n log n).
Here is a (somewhat intense) C++ implementation:
#include <boost/pending/disjoint_sets.hpp>
#include <boost/property_map/property_map.hpp>
#include <map>
#include <set>
#include <iostream>
typedef std::map<int, int> rank_t;
typedef std::map<int, int> parent_t;
typedef boost::associative_pro... |
3,848,312 | 3,848,314 | C++0x Peer Constructor in VC2010 | According to the C++0x spec, the following is legal
class A {
A(int i) : x(i) {}
A() : A(0) {}
int x;
};
But it fails to compile ("A" is not a nonstatic data member or base class of class "A") in VC 2010. Anyone know what's wrong?
| Visual C++ 2010 (also known as VC++ 10.0) as of this writing does not support delegating constructors, which is what your code snippet requires. VC++ 10.0 only has partial support for C++0x, and as of this writing, no compiler has implemented the entire C++0x feature set (although that will change soon, especially once... |
3,848,363 | 3,849,908 | What does C++ Graph mean in Intel Concurrent Collections? | I am reading the user guide that came with Intel concurrent collections, and I don't understand what they mean by the following sentence [Page 4 Section 1.1]:
You define an Intel Concurrent Collections for C++ graph which specifies the following:
Anybody know what do they mean by C++ Graph?
| They're not talking about a C++ graph - they're talking about an Intel Concurrent Collections for C++ graph.
The graph that's described here is not some general C++ concept, it's completely specific to this framework, and created as described in detail in the document, starting with the overview in Section 1.1.
|
3,848,427 | 3,853,407 | Qt: Best way to implement "oscilloscope-like" realtime-plotting | I'm working on a Gui-Module for Qt to plot realtime measurements like in an digital oscilloscope, based on Qwt. Everything works so far like it should, but maybe there are some features left to add ;-)
In the moment the data is stored column-wise in QVectors, together with one global timeReference QVector in one sepera... | photo_tom's answer pretty much sums it up: I'd stay away from QObjects for implementing the data handling and processing.
should you ever decide to use something else than Qt for your gui, you'll have a much harder time refactoring the code. Classes like QList and QVector can be replaced by STL counterparts without m... |
3,848,455 | 3,848,474 | Properly getting output from a pipe in C / C++ | I am writing C / C++ code to run a shell command and capture the output:
static const int BUFFER_SIZE=512;
// (...)
FILE* pipe;
char buffer[BUFFER_SIZE];
// (...)
if (!(pipe = popen(cmd.c_str(), "r"))) {
out("\nProblem executing command: " + cmd + "\n");
return 1;
}
while (!feof(pipe)) {
int read = fread(buf... | fread does not NUL terminate the buffer, so strlen is not appropriate.
Use the result read to limit your loop.
|
3,848,483 | 3,848,495 | Is there a good way to search by both key and value? | I am currently using map<int, int> in C++. I can check for the existence of a key without a problem but is there an efficient way to retrieve the keys that a particular value has as well? My purpose is to grab all the elements with a given value and then update their value.
| You might be interested in Boost.Bimap.
|
3,848,527 | 3,848,651 | error C2593: 'operator =' is ambiguous; Compiled fine on VS6, but I get that error on VS10 | I get the following error:
1>c:\documents and settings\krzys\desktop\desktop icons\ollydbg\plugins\odbgscript\OllyLangCommands.cpp(3602): error C2593: 'operator =' is ambiguous
1> c:\documents and settings\krzys\desktop\desktop icons\ollydbg\plugins\odbgscript\var.h(45): could be 'var &var::operator =(const lo... | Your variables map holds values of type var. sum isn't a var, so a conversion needs to be made.
The streamsize type in VC6 is a simple int and the var class will convert that to a var type implicitly.
In VS10, streamsize is an __int64, which you have no implicit conversion to a var for.
|
3,848,545 | 3,848,572 | My first encounter with Boost... Include errors | I am trying to run a boost example but I am getting the following error:
g++ bimap.cpp -o bimap
bimap.cpp:1:28: error: boost/config.hpp: No such file or directory
bimap.cpp:8:27: error: boost/bimap.hpp: No such file or directory
bimap.cpp: In function 'int main()':
bimap.cpp:27: error: 'boost' has not been declared
bim... | You must provide the paths to boost files to g++ itself.
Try this:
g++ bimap.cpp -I/apps/rhel5/boost_1_39_0/include/boost-1_39/ -L/apps/rhel5/boost_1_39_0/lib -Xlinker -rpath -Xlinker /apps/rhel5/boost_1_39_0/lib -o bimap
Or (solution by TokenMacGuy):
g++ bimap.cc $BOOST_INCLUDE $LINK_BOOST
|
3,849,052 | 3,850,201 | Is there an easy way to get shadows in OpenGL? | I recently created some landscape code and added some diffuse lighting to the scene, however, to my disappointment, there are no shadows. I looked around the web for hours looking for ways to get shadows in OpenGL, however they all seemed terribly complicated; and very unique to their own demo programs.
Are there any s... | No. Rasterization is very bad at this (even recent AAA games have noticeable shadow artefacts), but everybody lives with it.
Solutions include (approx. from easiest/poorest to best/hardest) :
No shadows. Simply account for occlusion with darker colors. xNormal, Blender.
If you want an approximate shadow for a characte... |
3,849,140 | 3,849,175 | copy constructor of base and derived classes | I have those two classes
///////////BASE CLASS
class Base{
public:
Base(int = 0);
~Base();
Base(Base&);
Base(Derived&); ////<-may be problem here?, note: I tried without this function
int valueOfBase();
protected:
int protectedData;
private:
int baseData;
};
... | Just a hint.
Does the following code give the same error?
class base{};
class derived: public base{};
int main()
{
derived d= base();
}
Yes? Why? Because there is no conversion from the base class to the derived class. You should define this conversion if you want your code to compile.
How about adding this to ... |
3,849,163 | 3,849,199 | Use USB to activate MOSFET/Relay | I am working on a personal project involving sending simple signals from my computer to a circuit via USB. Basically I am using the USB signal as the gate signal for a MOSFET which will in turn activate a relay to turn on/off various AC peripherals. For example if I want to turn on a light bulb for 5 seconds every minu... | USB is a bad fit for anything that doesn't have a USB interface at the other end of the wire. If you don't want to get into building your own USB device, I'd suggest buying a USB to serial adapter, which gives you two directly-controllable output lines (the flow control lines), or a USB to parallel adapter, which give... |
3,849,249 | 3,849,294 | Relax void * casting in C++ | In C, it's not an error to cast pointers to and from void *.
A major obstacle in porting to C++ is the need to cast pointers when returning from functions dealing with generic pointers such as malloc, and functions declared in my own code such as void *block_get(Blkno const blkno);.
My code however is intended to be co... | Maybe something like this? (untested, no compiler available, not using macros very often):
#ifdef __cplusplus
#define pointer_cast(type, pointer) reinterpret_cast<type>(pointer)
#else
#define pointer_cast(type, pointer) (type)(pointer)
#endif
|
3,849,340 | 3,849,437 | C++ l10n, i18n solution with GNU gettext, libunistring | I'm writing a C++ application which shall be locale independent, so I decided to use UTF-16 as my in-memory representation for strings/texts (the application should be as platform independent as possible). For localize the application's messages i want to use GNU's gettext library. Since this library seems to use GNU's... | Use UTF8 instead. see :
Should UTF-16 be considered harmful? - Yes
UTF8, UTF16, and UTF32
|
3,849,451 | 3,849,467 | base c'tor with derived argument | I created some class:
class Base{
public:
Base(int = 0);
~Base();
Base(Base&);
Base(Derived&); //<- here
int valueOfBase();
protected:
int protectedData;
private:
int baseData;
};
class Derived: public Base{
public:
Derived(int = 0);
Derived(Derived&);
~Derived();
private:
int derivedData;
};
#... | You probably need a forward declaration of Derived.
Try adding class Derived; above your Base class definition.
|
3,849,498 | 3,849,510 | When is VTable in C++ created? | I would like to know when is a vtable created?
Whether its in the startup code before main() or is it at some other point of time??
| A vtable isn't a C++ concept so if they are used and when they are created if they are used will depend on the implementation.
Typically, vtables are structures created at compile time (because they can be determined at compile time). When objects of a particular type are created at runtime they will have a vptr which ... |
3,849,626 | 3,858,326 | Understanding and using the Boost Phoenix Library with a focus on lazy evaluation | I just found out about the Boost Phoenix library (hidden in the Spirit project) and as a fan of the functional-programming style (but still an amateur; some small experience with haskell and scheme) i wanted to play around with this library to learn about reasonable applications of this library.
Besides the increasemen... | As requested, my comment (with additions and small modifications) as an answer...
I know your position exactly, I too played around with Phoenix (although I didn't dig in very deeply, mostly a byproduct of reading the Boost::Spirit tutorial) a while ago, relatively soon after catching the functional bug and learning ba... |
3,849,724 | 3,849,816 | technical aspects of 'isa' in c++ | what exactly does it mean from technical point of view, I understood that it means that my derived class can always be converted to base class, that's it? I read some materials without any reference to technical aspects, only philosophy! thanks in advance
| it means that my derived class can always be converted to base class
Actually it means better than that. int can always be converted to float, but that doesn't mean an int "is a" float. It just means a float can be constructed from an int. Likewise you can have user-defined classes that convert, but have no other relat... |
3,849,900 | 3,849,928 | Semicolon in namespace. Necessary? | when working with namespace, I need to finish it with a semicolon? When I put a forward declaration of a class into a namespace, for example, many people doesn't include a semicolon but, it seems to be optional.
Does semicolon add functionality or change the current functionality by adding or removing?
Thanks.
| If semicolon is optional it doesn't change functionality, otherwise it you omit it you'll get a syntax error.
namespace A {
class B; // forward declaration, semicolon is mandatory.
class B {
}; // class definition, semicolon is mandatory
class C {
} f(); // because otherwise it is a return type of... |
3,850,058 | 3,850,086 | friend in operator == or << when should i use it? | I feel I have a bit of a hole in my understanding of the friend keyword.
I have a class, presentation. I use it in my code for two variables, present1 and present2, which I compare with ==:
if(present1==present2)
Here's how I defined the operator == (in class presentation):
bool operator==(const presentation& p) const... | In the first case, your function operator== is a nonstatic class member. It has therefore access to private and protected member variables.
In the second case, the operator is externally declared, therefore it should be defined as a friend of the class to access those member variables.
|
3,850,085 | 3,850,124 | strange behavior of initialization in C++ | I have two classes Base and Derived from it:
class Base{
public:
Base(int = 0);
Base(Base&);
Base& operator=(const Base&);
protected:
int protectedData;
private:
int baseData;
};
/////////////DERIVED CLASS
class Derived: public Base{
public:
Derived(int = 0);
Derived(Derived&);
Derived(... | Change these constructors
Base(Base&);
Derived(Derived&);
Derived(Base&);
To take const references:
Base(const Base&);
Derived(const Derived&);
Derived(const Base&);
The former cannot accept temporary values, the latter can. The compiler wants to convert
Derived derived1 = base;
into
Derived derived1(Derived(base));... |
3,850,131 | 3,850,138 | Insert into 2D vector | Could you do the insert operation in one line along with allocating memory for internal vector?
vector <vector<int>> myvector;
int a[] = {0, 1, 2, 3, 4};
for (int index = 0; index < 2; index++)
{
myvector.push_back(vector<int>()); //allocate memory for internal vector
myvector[index].insert(myvect... | Yes, std::vector has a template constructor which takes a pair of iterators so you can use:
myvector.push_back( std::vector<int>( a, a + 5 ) );
A pair of pointers works as a pair of iterators.
|
3,850,284 | 3,850,313 | C++ Default copy constructor | I understand compiler won't generate default copy ctor if copy ctor is declared private in a class.
But can someone explain why compiler does that?
What happens if copy ctor is declared protected? Would compiler provide default copy ctor?
What happens if copy ctor is declared private but have a definition e.g. foo(con... | Any copy constructor declared in the class (be it private, public or protected) means the compiler will not generate a default copy ctor. Whether the one declared in the class is then also defined or not only controls whether code with the proper level of visibility into it can copy instances of the class (if not defi... |
3,850,316 | 3,851,114 | Why use exception instead of returning error code |
Possible Duplicate:
Exceptions or error codes
Hi,
I am looking for some guidelines on when to use return values v/s exceptions.
Many thanks in advance.
| Some of this might repeat content, but here are simple hints as to use one or the other:
No proper sentinel value
Your function might not be able to use a sentinel value to signal an error because all possible values are used by the function as valid answers. This may happen in different situations, most notably intege... |
3,850,377 | 3,850,415 | Complicated code for obvious operations | Sometimes, mainly for optimization purposes, very simple operations are implemented as complicated and clumsy code.
One example is this integer initialization function:
void assign( int* arg )
{
__asm__ __volatile__ ( "mov %%eax, %0" : "=m" (*arg));
}
Then:
int a;
assign ( &a );
But actually I don't understand wh... | In the case of your example, I think it is a result of the fallacious assumption that writing code in assembly is automatically faster.
The problem is that the person who wrote this didn't understand WHY assembly can sometimes run faster. That is, you know more than the compiler what you are trying to do and can somet... |
3,850,566 | 3,850,587 | ISO C++ forbids declaration of 'Game' with no type - possible include problem? | compiler output:
g++ -Wall -g main.cpp `sdl-config --cflags --libs` -lSDL_mixer
In file included from Game.h:8,
from main.cpp:1:
DrawableObject.h:11: error: ISO C++ forbids declaration of ‘Game’ with no type
DrawableObject.h:11: error: expected ‘;’ before ‘*’ token
DrawableObject.h:13: error: expected ... | The problem is that you are missing a closing brace for the while loop in Game.h
Update: As other's have mentioned you also need to resolve you circular include of Game.h in DrawableObject.h. You can simply put a forward declaration of the Game type in the DrawableObject header, see @ybungalobill and @Lou Franco answer... |
3,850,711 | 3,853,509 | Virtual tables when copying objects | #include <iostream>
#include <string>
class A
{
public:
A(int a) : _a(a) {}
virtual ~A() {}
virtual void f() const {std::cout << _a << std::endl;}
private:
int _a;
};
class B : public A
{
public:
B(int a, int b) : A(a), _b(b) {}
virtual void f() const {std::cout << _b << std::endl;}
private:
... | Firstly 'virtual table' is not a standard C++ concept. It is a highly implementation specific mechanism to implement dynamic binding and implement virtual functions.
Having said that,
But i thought that the virtual table
of 'ref' now should be as a virtual
table of 'b' so 'ref.f();' should call
the function
Th... |
3,850,817 | 3,850,827 | develop C++ without Xcode IDE | I want to develop C++ programs on mac os and I have installed Xcode with a bunch of frameworks.
However I would like to write code without Xcode IDE but just write my own makefile and directly compile/link with gcc (shipped with Xcode).
Take a opengl program as example. I tried to compile it with the command:
gcc -I/... | Use g++ to compile C++. It's the C++ front-end for GCC. E.g.:
g++ -I/usr/include/ -L/usr/lib -framework OpenGL -framework GLUT -lm main.cpp
|
3,850,847 | 3,851,003 | non density based Data clustering algorithm | I'm working on a cluster analysis program that takes a set of points S as an input and labels each point with that index of the cluster it belong to. I've implemented the DBScan and OPTICS algorithms and they both work as expected.
However, the results of those algorithms can be very different depending on the initial ... | In general a set of points can be assigned to clusters in more than one way (e.g. they can all be assigned to one big cluster, or divided into two or three), so you have to have some parameters.
Why do you object to MinPts and Epsilon? If you don't like what happens when you change them, don't change them. Seriously.
E... |
3,850,987 | 3,850,997 | Declare a class/struct | For example, i have a struct and I'm using static function of class to initialize its members. how can i tell the complier that the class exists but it is defined after the structure S?
struct S
{
S()
{
x = C::GetX(); //static functions, GetX() and GetY()
y = C::GetY();
}
int x; int y;
};
... | Put C first.
Without more context, it's hard to answer in more depth.
struct S;
class C
{
/.... /
};
struct S
{
S()
{
x = C::GetX(); //static functions, GetX() and GetY()
y = C::GetY();
}
int x; int y;
};
Or, you might need to define S::S outside the class S block.
struct S
{
S();
... |
3,851,034 | 3,851,045 | what is the size of an abstract class and why can't we create objects of an abstract class? | what is the size of an abstract class and why can't we create objects of an abstract class?
| Because otherwise it wouldn't be "abstract". The whole point of an abstract base class is that it is not meaningful to instantiate it; instead one must define derived subclasses, and instantiate them instead.
Abstract classes, therefore, have no size (but that's not to say that they don't contribute to the size of its... |
3,851,052 | 3,851,188 | Is copy constructor used for object initialization? How does it works and what is the difference B/W deep copy and shallow copy? | Is copy constructor used for object initialization? How does it works and what is the difference B/W deep copy and shallow copy?
| shadow copy : the new object points to the same memory location pointed by the old object, which means that any change of the value of one of the both objects will affect the other one. particulary if you dispose one of the both object, the other will be dispose too.
deep copy : a memory is allocate to the new object a... |
3,851,061 | 3,852,338 | Listening for IPv6 multicasts on Linux | I'm trying to get a simple multicasting example to work on Linux (I've
tried both RHEL 4 2.6.9 and Ubuntu 8.04 2.6.24). The general idea is
that I would like the server to bind to a unicast address and then add
itself to the group ff02::1. I would then like it to receive
multicasts sent to ff02::1. The code below works... | Binding filters incoming addresses, so if you bind to an adapter address you only get packets with matching destination address: i.e. unicast packets, if you bind to a multicast address you will only get multicast packets; to get multicast and unicast packets you must bind to INADDR_ANY or IN6ADDR_ANY.
|
3,851,069 | 3,851,104 | Cannot assign pointer in a self-referential object in Visual Studio 2010 | I am learning C++ and i currently have some questions that i don't know the answers. I create this header file Object1.h and can compile this file but when i run the Test.cpp, Visual Studio throw an error because of access violation by *sibling. The strange thing is I can run it using Dev C+ and it return only value 2.... | Using operator * assumes that you deal with some data resided by address stored in this variable. Let's review your code:
*sibling = *p;
You trying to copy by value. This is wrong because sibling points to nowhere. It is even not a NULL, it is unpredictable. The correct line will be:
sibling = p;
So you tell that wou... |
3,851,181 | 3,851,201 | Define array, then change its size | I come from a java background and there's something I could do in Java that I need to do in C++, but I'm not sure how to do it.
I need to declare an array, but at the moment I don't know the size. Once I know the size, then I set the size of the array. I java I would just do something like:
int [] array;
then
array =... | In C++ you can do:
int *array; // declare a pointer of type int.
array = new int[someSize]; // dynamically allocate memory using new
and once you are done using the memory..de-allocate it using delete as:
delete[]array;
|
3,851,221 | 3,851,231 | 0x2e2e2e2e in GDB backtrace? | I've got a SIGSEGV I'm trying to track down in my code, but I'm getting strange backtraces like this out of GDB:
#1 0x00407d15 in print_banner (msg=0x2e2e2e2e <Address 0x2e2e2e2e out of bounds>)
at ../include/test_util.hh:20
#2 0x2e2e2e2e in ?? ()
#3 0x2e2e2e2e in ?? ()
#4 0x2e2e2e2e in ?? ()
#5 0x2e2e2e2e in ... | You get this when you've corrupted the stack, and overwritten stuff that gdb needs.
Sounds like you've overflown a buffer with a bunch of "...." characters.
Tools like valgrind can more easily help you diagnose such problems.
|
3,851,352 | 3,851,367 | Floating point and integer ambiguity | I have a function (and a constructor) that should be able to take integer and floating point values. In fact I want it to take an int64_t or a long double, so what I want is,
class Foo {
public:
Foo(int64_t value=0);
Foo(long double value);
};
However if I do this and try Foo f = 1; the compiler complains ... | The type of the 1 literal is int. Either constructor is going to need a conversion, int to int64_t vs int to long double. The compiler doesn't think either of them is preferable so it complains. Solve it by adding a Foo(int) constructor. Or casting the literal, like (int64_t)1.
|
3,851,361 | 3,851,379 | Difference between pointer and smart pointer | Can you tell me what is wrong with this piece of code? I got asked this in an interview and I am not sure what's wrong with it
tClass is a test class with a method printSomething that prints members of tClass.
tClass * A = new tClass();
f(A);
A->printSomething();
auto_ptr<tClass> * B = new tClass();
f(B);
B-> printS... | auto_ptr is a type of smart pointer that operates under the premise that exactly one party owns the pointer, and if that owning party goes out of scope, the pointer gets deleted.
When you pass an auto_ptr to a function, you are "Giving" the function that pointer, and so you don't have it anymore. when you dereferenc... |
3,851,584 | 3,851,595 | How do I avoid pointer invalidation in my insert function? | In my data structures course, we are creating a basic vector class. In my header, there is a member function for inserting new values into the vector. If the capacity of my vector is big enough for the insertion of one value, the program runs fine. However, if the vector needs to grow, I run into pointer errors. After ... | Change the pos iterator into an index instead, and use that.
size_t index = pos - begin();
// do resize
pos = begin() + index;
If you're worried about iterators invalidating in general, don't. It's unavoidable, at least in this style of dynamic array, and std::vector works exactly the same.
|
3,851,602 | 3,851,615 | interface of the list in c++ | I found some interface for the list:
and there I found this constructor
template<typenameT>
...
list(size_tnum, constT& val = T());
...
can somebody explain what is this: constT& val = T()
thanks in advance
| const T& val = T()
This describes a parameter that is taken by const reference, but is optional because the parameter is declared with an initialier. If not supplied then a value initialized temporary (T()) is used.
The list constructor you've found initializes a list with num copies of the val parameter.
|
3,851,604 | 3,852,748 | C++, Access Violation using OpenCV to get RGB value of pixel | I'm trying to use OpenCV to find the RGB values of a pixel in an image. so far I've tried the following:
int blue = ((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 0];
int green = ((uchar *)(img->imageData + y*img->widthStep))[x*img->nChannels + 1];
int red = ((uchar *)(img->imageData + y*img->widthSt... | The problem probably caused by
IplImage *slice = cvLoadImage("test.png");
if the function failed, variable slice will be NULL, and any further dereferencing will leads to access violation.
Since opencv's dll may be installed on different path than your running application, it is advisable to provide "absolute file pat... |
3,851,628 | 3,851,833 | Intercept mouse input | I was wondering if there is a way to intercept and modify mouse input before it gets to windows?
What I'm wanting to do is intercept mouse motion events, apply some custom scaling and acceleration to the values, and then continue passing them along. I'd need something that can do this before the inputs get to the raw i... | In order to affect all mouse input, including DirectInput, during logon and the SAS screen, etc., you'll need to load a filter driver into the mouse driver stack.
Other people have done it, for example http://www.maf-soft.de/mafmouse/
There should be a moufiltr sample in the Windows DDK which you can use as a starting ... |
3,851,922 | 3,851,934 | boost::gil Interleaved_view | I'm having some trouble figuring out the boost image library.
I could not find any exact documentation on how to use the interleaved_view function included in the boost::gil library. More specifically, I don't know exactly what binary format the raw data is supposed to be stored in.
The only mention of it I could find... | Sorry guys, I just realized immediately after posting that I've been working with matlab for way too long... I wrote the array in column major form... Ugh I feel stupid
|
3,852,252 | 3,852,345 | How to store OpenGL Primitives in a tree data structure in C++? | I'm new to OpenGL and C++. Say I start with a 2D square (on the very left) like shown in the picture below. I want to make it interactive with the glutKeyboardFunc() so when I press a number a new box will draw next to the corresponding edge.
Figure the best way to do this is to have a tree structure that hold all the... | If I understand your question, you can make a class that represents the box, such as:
class Box {
public:
void Move(int newx, int newy) {
x = newx;
y = newy;
}
void Resize(int newx, int newy) {
w = newx;
h = newy;
}
int getX() { return x; }
int getY() { return y; }
int getW() { return w; }... |
3,852,584 | 3,852,593 | Problem with linking, c++ member function to C callback | I'm trying to interface a c++ member function with a legacy C library taking a function pointer - I can't see why this keeps coming up with link errors, Can anyone see why ?
link errors
/tmp/ccl2HY1E.o: In function `VerifyWrapper::verifyGlue(int)': callback.cpp:(.text._ZN13VerifyWrapper10verifyGlueEi[VerifyWrapper::ver... | static Verify* vfy;
You need to define this static member, the declaration [that you have provided] is just not enough. The code won't pass the linker because the definition [of the static member] is missing.
Define vfy outside the class.
Verify* VerifyWrapper::vfy; //definition
|
3,853,019 | 3,853,076 | how to compare two endpoint address with C++ in windows: | bool checkSockaddr(sockaddr_in a, sockaddr_in b)
check if they two have the same address information.
| bool checkSockaddr(sockaddr_in const &a, sockaddr_in const &b) {
return a.sin_addr.S_un.S_addr == b.sin_addr.S_un.S_addr;
}
|
3,853,263 | 3,853,280 | Why I can apply array subscript access syntax on non array |
Possible Duplicate:
In C arrays why is this true? a[5] == 5[a]
Consider the following code able to compile under VC2008.
int i = 0;
int *j = 0;
int k = 0;
i[j]; // OK?!?!
i[k]; // Compile Error.
I was wondering, what is the meaning of i[j] in this content?
| i[j] equals to j[i]
Therefore it's doing *(j + i) which is actually valid since j is a pointer.
This doesn't apply for k because it isn't a pointer.
|
3,853,339 | 3,853,462 | Any reason to prefer memset/ZeroMemory to value initialization for WinAPI structs? | In Win32 programming a handful of POD structs is used. Those structs often need to be zeroed out before usage.
This can be done by calling memset()/ZeroMemory()
STRUCT theStruct;
ZeroMemory( &theStruct, sizeof( theStruct ) );
or by value initialization:
STRUCT theStruct = {};
Although the two variants above are not e... | I always use:
STRUCT theStruct = {}; // for C++, in C use {0}
It's shorter, standard, therefore more elegant, and I don't really care about the theoretical differences. We are talking about code for a concrete OS here.
Another advantage is you can also immediately set the struct size in the first member like this:
ST... |
3,853,382 | 3,853,439 | STL in embedded environment | I am a C++ programmer and over the years have been subjected to hearing the notion that STL is not good for use in embedded environments and hence usually prohibited in usage for embedded environment based projects.I believe STL libraries like Boost are far more powerful and provide a much more faster & less error pron... | STL has quite a few problems with it(as documented here by EASTL), on an embedded system, or small scale system, the main problem is generally the way in which it manages (its) memory. a good example of this was the PSP port of Aquaria.
My advise though is first test, before following assumptions, if the test are shows... |
3,853,563 | 3,854,215 | How to open a file which is already open in exclusive mode? | I want to access a file which is already opened with exclusive access by some other process (not under my control). I know that the I/O manager will not grant my request, as some other process is holding the lock (with exclusive access).
Is there any way by which I can bypass the checks (such as file opened in exclusiv... | The backup api (volume shadow copy) may help you to obtain a copy of that file.
|
3,853,828 | 3,853,862 | A ThreadPool library in C++ | I am looking for a good and stable threadpool library for C++ that's fairly well documented. I know about the Native Windows thread pool API and the newer Vista Thread Pool API, however my program requires some backward compatibility, so perhaps an outside library I can provide with the program is better.
I have looke... | A portable threadpool library that claims to be 'production ready'. You may want to check that out.
|
3,853,834 | 3,854,182 | Monitor selections in any application | I want to monitor all text selections made in any application by the user. Is that possible? I would prefer a solution in .net, but vanilla C++ is OK.
If not, can I monitor all text copy operations (CTRL+C) from a .net application?
similar question: In C#, is there a way to consistently be able to get the selected tex... | A "selection" is not a universal concept, each control may handle it in its own way. If you want to intercept every selection, you could place a global hook on windows messages, and intercept the notifications relative to "known" edit controls (the standard edit control, the RichEdit control, ...), by filtering out the... |
3,853,913 | 3,853,935 | What Linux IPC to use between a c program and a C++ Qt app? | I have a old school c program that now and then
need to tell a C++ Qt based application about some "events" that has occurred on my system.
But when I started to work with this problem I noticed that some ipc techniques is quite easy to use in the c program.
And then we have some Qt specific styles that works quite we... | What about named pipes? You can operate on them just like on regular files (creation is a bit different of course), and I bet both old ANSI C programs and new Qt C++ programs can operate on files.
|
3,854,113 | 3,854,144 | What is an opaque value in C++? | What is an "opaque value" in C++?
| An example for an Opaque Value is FILE (from the C library):
#include <stdio.h>
int main()
{
FILE * fh = fopen( "foo", "r" );
if ( fh != NULL )
{
fprintf( fh, "Hello" );
fclose( fh );
}
return 0;
}
You get a FILE pointer from fopen(), and use it as a parameter for other functions, ... |
3,854,419 | 3,854,466 | Overloading the subscript operator "[ ]" in the l-value and r-value cases | I have overloaded [] operator in my class Interval to return minutes or seconds.
But I am not sure how to assign values to minutes or second using [] operator.
For example : I can use this statement
cout << a[1] << "min and " << a[0] << "sec" << endl;
but I want to overload [] operator, so that I can even assign value... | Return a reference to the member in question, instead of its value:
long &operator[](int index)
{
if (index == 0)
return seconds;
else
return minutes;
}
|
3,854,496 | 3,854,549 | How do I get the current UTC offset (time zone)? | How do I get the current UTC offset (as in time zone, but just the UTC offset of the current moment)?
I need an answer like "+02:00".
| There are two parts to this question:
Get the UTC offset as a boost::posix_time::time_duration
Format the time_duration as specified
Apparently, getting the local time zone is not exposed very well in a widely implemented API. We can, however, get it by taking the difference of a moment relative to UTC and the same ... |
3,854,519 | 3,854,660 | C++ and Objective-C autorelease problem | I have three layers, the bottom layer is written in C++ and the other two middle and top layers are both in Objective-C.
The C++ layer stores a reference to a class in the middle layer, and the middle layer also stores a reference to a class in the top layer.
Upon receiving a request from the middle layer, the bottom l... | As far as I understood your question, you have the bottom layer in a thread which calls the middle layer. As you already discovered you have to have an autorelease pool if you want to use the Cocoa framework (it's not about Objective-C ;)).
You should either create one at thread creation or create and release one for e... |
3,854,636 | 3,854,765 | gcc optimizations cause app to fail | I'm having a real strange problem using GCC for ARM with the optimizations turned on.
Compiling my C++ application without the optimizations produces an executable that
at runtime outputs the expected results. As soon as I turn on the
optimizations - that is -O1 - my application fails to produce the expected results... | Generally speaking, if you say "optimization breaks my program", it is 99.9% your programm that is broken. Enabling optimizations only uncovers the faults in your code.
You should also go easy on the optimization options. Only in very specific circumstances will you need anything else beyond the standard options -O0, -... |
3,854,853 | 3,854,873 | implementation of string class | I'm interested in the implementation of the reverse iterator with rbegin(), rend() and operator++ of the class string, I can't find it in google, how can I do it? thanks in advance for any help or any link
| You could look in the implementation header files. (e.g. /usr/include/c++/4.1.2/string on Linux). This will typically just pull in a load of other headers where the real meat lies, such as bits/basic_string.h.
I don't know where they reside for e.g. VC++, but you can usually just get Intellisense to find it by creati... |
3,854,917 | 3,870,640 | Low level Bluetooth Programming in C++ | I need a library (or API, ...) to do some low level Bluetooth programming using C++. Any reference or rich link will be great!
And i prefer to work in linux based opreration systems...
Thanks in advance... :)
| http://www.bluez.org/ for Linux
http://inthehand.com/content/32feet.aspx for Windows
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.