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 |
|---|---|---|---|---|
7,373,965 | 7,374,508 | Class member function declaration doubt | I'm reading a C++ tutorial and I've ran into this sentence:
The only difference between defining a class member function
completely within its class or to include only the prototype and later
its definition, is that in the first case the function will
automatically be considered an inline member function by the ... | The best solution is to separate interface and implementation. Interface is your h-file. Put only prototypes there. Implementation goes to cpp-file. This approach has the following advantages:
Compilation goes faster because there is no need to compile function bodies several times.
Header dependency is simpler becaus... |
7,374,285 | 7,374,312 | ReadProcessMemory Always fails with GLE: 299 | Could someone please help me, I do not know why the ReadProcessMemory function fails and GetLastError = 299. Here is my code, I can't see that im doing anything wrong.
if(ReadProcessMemory(hProcess, (void*)0, IDH_Buffer, sizeof(IMAGE_DOS_HEADER), 0) != true)
std::cout << "Failed to read from Process, GLE=" << G... | Quoting from MSDN on Win32 error codes:
ERROR_PARTIAL_COPY
299 (0x12B)
Only part of a ReadProcessMemory or WriteProcessMemory request was completed.
My guess is the address you specified contained some valid data, but somewhere between that address and (address + length of copy), there was no memory mapped.
See wikipe... |
7,374,337 | 7,374,383 | Image processing in C++ | I am opening a 3.5 MB file in C reading it into an unsigned char array Image data which I have initialized as follows:
unsigned char *** Imagedata;
Imagedata = new unsigned char**[1278];
for(int i=0; i<1278; i++){
Imagedata[i]= new unsigned char*[968];
for(int j=0; j<968; j++){
Imagedata[i][j]= new unsi... | ifile>>Imagedata[i][j][k];
This is formatted input, it eats 'whitespace' characters even though you specified ios::binary. Use
Imagedata[i][j][k] = ifile.get();
Even better, allocate one big chunk of memory for the whole file and read it by one read call. What you do now is allocating a pointer for each pixel, which ... |
7,374,403 | 7,374,440 | c++ class member of same type | I have the following situation:
class Foo
{
public:
static const Foo memberOfFoo;
........
}
So the thing is I can't initialize it in the same line where I declared it, and, I can't initialize it via Initializations List in the constructor, does anyone know what to do?
| Put this outside of the class definition then:
const Foo Foo::memberOfFoo = whateverValue;
That is the definition of Foo::memberOfFoo, which can supply an initializer and has to go into the .cpp file (like any other definition of objects, it can only appear once in the whole program, otherwise you will get linker erro... |
7,374,581 | 7,374,607 | Initialization lists in constructor | I've heard that the advantage of using initialization lists in constructor would be that there will be no extra copies of class type objects. But what does it mean for the following code in class T constructor? If i comment the assignment and use initialization lists what would be the difference?
#include <iostream>
us... | It's exactly what you already said. If you don't use the initializer list, then the default constructor will get called first, and then the assignment operator will get called.
In your example, this is relatively benign (the compiler may even optimise this, I think). But in other cases, it's simply not possible to av... |
7,374,627 | 7,374,723 | Unclear segmentation fault in a constructor | I have built a constructor for a matrix object. The data is being stored in an array of struct val, which in turn hold position (in the matrix) and value. This is the code:
SparseMatrix::SparseMatrix(const int numRow, const int numCol, vector<double> fill):
Matrix(numRow,numCol)
{
_matrix = new vector<val*>... | This is the std::vector<val *> constructor that is being used to construct *_matrix:
explicit vector ( size_type n, const val *& value = val *(), const std::allocator<val *>& = std::allocator<val *>() );
The invocation of that constructor with n set to fill.size() creates a new std::vector<val *> having fill.size() de... |
7,375,003 | 7,375,035 | How to convert HICON to HBITMAP in VC++? | How to convert HICON to HBITMAP in VC++?
I know this is an FAQ but all the solutions I've found on Google don't work. What I need is a function which takes a parameter HICON and returns HBITMAP.
Greatest if possible to make conversion to 32-bit bitmap even the icon is 24-bit, 16-bit or 8-bit.
This is the code, I don't... | I don't have code readily available to share, but I think this is pretty easy. You have to create the HBITMAP, create a device context, select the bitmap into the DC (this will make the bitmap the drawing area for this DC). Finally call the DrawIcon() function to draw your icon on this DC. After that detach the bitmap ... |
7,375,098 | 7,375,121 | Circular dependencies in c++ | Say I have these two classes:
// a.h
#include "b.h"
and:
// b.h
include "a.h"
I understand there is a problem over here, but how can I fix it and use a objects and their methods in b class and vice versa?
| You can use forward declarations, like this:
class B;
class A
{
B* ThisIsValid;
}
class B
{
A SoIsThis;
}
For more information, see this SO question.
As for the preprocessor #includes, there's likely a better way to organize your code. Without the full story, though, it's hard to say.
|
7,375,446 | 7,375,453 | Jumping to a specific line in code using C | Sorry if this question is silly, but I can't seem to find the answer on Google. I haven't done C programing in a while and for the life of me remember how, in C or C++, to jump back (or forward) to a specific line in code. If I remember right, there was a way to do this.
Thanks for the help!
Cheers!
| The infamous goto, in conjuntion with labels.
label_name:
goto label_name;
Before using it, search for 'goto considered harmful'.
|
7,375,522 | 7,375,611 | Error: method was not declared in this scope (but it is included) | I have two folders, f1 and f2, and they are on same level (have same folder for parent). In f1 I have source code of my project, and in f2 I have unit tests.
The problem occurs when I try to include file from my project into unit test class. I just get this:
natty:/tmp/test/f2$ qmake-qt4 .
natty:/tmp/test/f2$ make
g++... | Your problem is that you have duplicated the header guards from f1/common.h in f2/tcommon.h.
Change these to (in tcommon.h):
#ifndef TCOMMON_H
#define TCOMMON_H
//...
#endif // TCOMMON_H
and the problem is fixed, the program builds and you can run it. In response: fixed.zip (see source of this answer)
|
7,375,555 | 7,375,710 | generalized copy constructor in an inner class | I'd like to specify a conversion from A<T>::B to A<U>::B.
template<typename T>
struct A
{
struct B
{
B() {}
template<typename U>
B(const typename A<U>::B& rhs) {}
};
};
int main()
{
A<int>::B x;
A<double>::B y = x;
}
I thought this would do it, but I get the compiler err... | Slightly amended source, to demonstrate that this is about the limits to the type deduction system:
template<typename T>
struct A
{
struct B
{
B() {}
template<typename U>
B(const typename A<U>::B& rhs) {}
template<typename U>
B& operator=(const typename A<U>::B&... |
7,375,822 | 7,376,258 | How to get screenshot of WPF application in VC++? | How to get screenshot of WPF application in VC++?
In VC++, I have HWND to a window which is WPF application. Traditional method using GDI PrintWindow doesn't work properly on WPF application (get a black screen when the WPF is slow in rendering). Any other method to take screenshot of a WPF application as HBITMAP?
| Would GetDC & BitBlt change anything for the GDI+ scenario??
|
7,375,837 | 7,375,876 | Why can't I assign a value to a variable in a namespace? | My code is like below, when I compile it , I receive this error :
two.cpp:5: error: expected constructor, destructor, or type conversion before '=
' token
#include <iostream>
using namespace std;
namespace a1{
int a=3;
a=4;
}
int main(){
cout << a1::a<<endl;
}
I encountered this problem when I defined... | The purpose of namespaces is to avoid conflicting names. So surround your variable and class declarations with namespaces. But namespaces by themselves don't provide the scaffolding for running code. What is going on with your a=4; statement ? Where is that supposed to execute ? You need to put it in a function or meth... |
7,376,452 | 7,376,459 | Enums and classes - Run time error !! | My aim before writing this code was to just practice and learn more about C++ .
The code consists of a class ball which has a ball's properties like colour , size , weight and also the 'brand' and price of the ball .
#include<iostream>
#include<string>
using namespace std;
class ball
{
private:
int price; ... | You call brand(NULL) on a std::string, that's the runtime error you are getting. It's calling the std::string constructor that takes a char const*, to create from a C string, and it can't be NULL. To construct an empty std::string simply call brand() in your initialization list, or even skip it since if you do the defa... |
7,376,482 | 7,376,504 | Best implementation of the missing unary std::copy | C++11 introduces semantics to avoid unnecessarily copying objects, and std::move to apply those semantics when otherwise a copy would occur. However, there are now also some cases where a copy is required, but not the default.
Consider this naive implementation of reverse, for example. Because range-based for uses perf... | The return type you're computing is better known as typename std::decay<T>::type. Other than that, use std::forward in the body to reap the full benefits of perfect forwarding:
template<typename T>
typename std::decay<T>::type
val(T&& t)
{ return std::forward<T>(t); }
|
7,376,751 | 7,376,853 | JIT optimizer for C/C++ | I was reading about the advantages of JIT over precompiled and one of those mentioned was that a JIT could adjust branch predictions based on actual runtime data. Now it's been a long time since I wrote a compiler in college, but it seems to me that something similar can be achieved for precompiled code also in most c... | Most modern CPU support branch prediction. They have a small cache which allow the CPU to notionally give you the benefits of re-ordering at runtime. This cache is fairly limited in size, but may mean you don't get as much benefit as you might imagine. Some CPUs can even start executing both branches and discard the... |
7,376,985 | 7,376,997 | invalid initialization of non-const reference when returning an array element | I'm writing a class that wraps a dynamically allocated array and I'm trying to write the operator[] function. Currently I have:
bool& solution::operator[](unsigned int pos)
{
if(pos < _size)
{
return this->_data[pos];
}
else
{
return false;
}
}
But I get the following error from g++:
error: invalid... | Its because the boolean literalfalse which is a rvalue, cannot be bound to non-const reference bool& which is the return type of operator[].
Simply change the return type from bool& to bool, the error will disappear. But that isn't going to solve your problem, as you said,you want to return reference of the element, s... |
7,376,988 | 7,377,042 | Image processing in C++ | I want to read a raw file, which has 3 interleaving and has a size of about(3.5MB) large into a three dimensional array.. the code that I am using to read the file is:
ifile.open(argv[2], ios::in|ios::binary);
for(int i=0; i<1278; i++){
for(int j=0; j<968; j++){
for(int k=0; k<3; k++){
Imagedat... | First, image files are usually stored, in order of smallest jump to largest, color values, column, row order. You are not reading them in that order.
ifile.open(argv[2], ios::in|ios::binary);
for(int j=0; j<968; j++){
for(int i=0; i<1278; i++){
for(int k=0; k<3; k++){
Imagedata1[i][j][k]=ifile.g... |
7,376,996 | 7,380,655 | Registering Windows context menu handler provided by Microsoft's All-In-One framework (CppShellExtContextMenuHandler project) | I've been using the CppShellExtContextMenuHandler sample project from Microsoft's All-In-One framework to add a custom menu item + icon to windows's context menu.
However, it seems that I can't register the DLL provided by this sample on other computers than mine. The DLL, compiled on a Windows 7 x86 machine from unmo... | Finally found the answer, thanks to Choosing a Deployment Method on MSDN.
To make the DLL file compiled from the CppShellExtContextMenuHandler sample work on non-dev computers, you need to accompany it with the VC++ Runtime DLLs it depends on.
I used the wonderful tool on a client's (non-dev) machine to get the name of... |
7,377,006 | 7,377,096 | getting an element from a tuple |
Possible Duplicate:
Why doesn't ADL find function templates?
Calling get does not seem to invoke argument dependent lookup:
auto t = std::make_tuple(false, false, true);
bool a = get<0>(t); // error
bool b = std::get<0>(t); // okay
g++ 4.6.0 says:
error: 'get' was not declared in this scope
Visual Studio ... | It's because you attempt to explicitly instantiate get function template, by providing 0 as template argument. In case of templates, ADL works if a function template with that name is visible at the point of the call. This visible function template only helps triggering ADL (it may not be used actually) and then, a bes... |
7,377,257 | 7,377,294 | Does mremap work with malloc? | Is
void * mremap(void *old_address, size_t old_size , size_t new_size, unsigned long flags);
compatible with malloc()?
GCC (C++) and using Linux.
Thanks.
| No, it is not. Apart from the fact that malloc doesn't need to give you an address at a page border (which is what mremap expects), it would be dangerous to mess with memory mappings from malloc without malloc knowing you did it. Use realloc instead.
|
7,377,449 | 7,377,552 | writing xml file with xercesc::DOMWriter | I am trying to write a xml file using xercesc::DOMWriter in c++.
But I get a compilation error when writing the line:
xercesc::DOMWriter *theSerializer = ((xercesc::DOMImplementationLS*)impl1)->createDOMWriter();
error: DOMWriter is not a member of xercesc
I have the following includes:
#include <xercesc/util/TransSer... | Use macro XERCES_CPP_NAMESPACE_USE to import symbols from Xerces's namespace to global namespace.
Alternatively, you can use XERCES_CPP_NAMESPACE::
|
7,377,585 | 7,377,658 | Template class assignment operator class | I have a TemplateArray and a CharArray class.
How do I make it so the templatearray's assignment operator only copies in from the chararray class when the templatearray is of the same type (I.E. char) or similar type (I.E. unsigned char) to chararray?
TemplateArray and CharArray are functionally the same (except CharAr... | It looks like you need a specialization of TemplateList::operator=:
template<>
TemplateList& TemplateList<char>::operator=(const CharArray &ItemCopy)
{
// Do the copying here, you don't provide enough
// information for a practical suggestion
}
|
7,377,772 | 7,377,789 | c++ compile error "redefinition of", need help to find it | it's a long time that I don't use C++ and I'm not so friendly with it. I'm resuming an old project of mine and trying to compile it, but I get the following error output launching Makefile:
g++ -W -ggdb3 -Wall -ansi -pedantic -c main.cpp
In file included from Entity3d.h:4,
from SceneManager.h:10,
... | You've used the same name for two parameters:
... Vector3d delta, Vector3d delta);
|
7,377,773 | 7,377,784 | How can I get a pointer to the first element in an std::vector? | I want to write data from an std::vector<char> to a socket, using the write function, which has this prototype:
ssize_t write(int, const void *, size_t);
The second argument to this function must be a pointer to the first element in the std::vector<char>. How can I get a pointer to this element?
I tried std::vector::f... | &mv_vec[0]
or
&my_vec.front()
|
7,377,912 | 7,378,146 | OpenGL define vertex position in pixels | I've been writing a 2D basic game engine in OpenGL/C++ and learning everything as I go along. I'm still rather confused about defining vertices and their "position". That is, I'm still trying to understand the vertex-to-pixels conversion mechanism of OpenGL. Can it be explained briefly or can someone point to an articl... | This is rather basic knowledge that your favourite OpenGL learning resource should teach you as one of the first things. But anyway the standard OpenGL pipeline is as follows:
The vertex position is transformed from object-space (local to some object) into world-space (in respect to some global coordinate system). Thi... |
7,378,087 | 7,378,202 | How to efficiently copy a std::string into a vector | I have a string
std::string s = "Stack Overflow";
That I need to copy into a vector.
This is how I am doing it
std::vector<char> v;
v.reserve(s.length()+1);
for(std::string::const_iterator it = s.begin(); it != s.end(); ++it)
{
v.push_back( *it );
}
v.push_back( '\0' );
But I hear range operation are more efficie... | If you really need a vector (e.g. because your C function modifies the string content), then the following should give you what you want, in one line:
std::vector<char> v(s.c_str(), s.c_str() + s.length() + 1);
Since c_str() returns a null-terminated string, you can just copy it whole into the vector.
However, I’m not... |
7,378,266 | 7,378,796 | Upgrading boost::shared_lock to exclusive lock | Could someone please explain the correct usage for boost::upgrade_lock. The following code results in a deadlock
//Global
typedef boost::shared_mutex Mutex;
typedef boost::shared_lock<Mutex> ReadLock;
typedef boost::upgrade_lock<Mutex> UpgradeLock;
typedef boost::upgrade_to_unique_lock<Mutex> WriteLock;
Mutex sharedMu... | In the boost::shared_mutex class (which implements the UpgradeLockable concept), a single thread should not attempt to acquire both a shared and an upgradeable (or unique) lock. At any time, the UpgradeLockable can have N shared locks held (via lock_shared), and 1 upgradeable lock (via lock_upgrade). The upgradeable ... |
7,378,275 | 7,378,292 | Pass 1 D array to a function that takes 2 D array | I have a function that takes 2 D character array as parameter
class listview{
int numColumn;
void func(char** data)
{
}
};
The func does not take dimensions, because it is fixed as a data member in the object of which it is member. Its job is to insert a row consisting of a number of columns in a li... | That depends entirely on the function and what it does. Why does it take a char**? Perhaps because it takes an output or an input/output parameter? Or perhaps it treats the parameter as a 2D character map(this is unlikely since it doesn't take the dimensions). How does it interpret its parameter? Does it index the poin... |
7,378,389 | 7,378,413 | compile c/c++ online [security issue] | I'm trying to compile c/c++ program online by gcc compiler.
when user enter c/c++ code,I will make temp file (temp.cpp) and after that I will compile it by exce('gcc temp.cpp'); php function.after that I will run it by exce() function too.
now how can I sure user c/c++ code don't be to hurt my website?how can I preve... | As long as you don't execute the compiled program on your server, it's fine.
If you do run the program on your server, then you'll have to sandbox it, which can be difficult. See codepad's about page to see how they do it.
|
7,378,492 | 7,379,123 | c++ array initialization |
Possible Duplicate:
array initialization, is referencing a previous element ok?
I wonder if its safe to do such initialization in c/c++ standard:
int a = 5;
int tab[] = { a , tab[0] + 1 , tab[1] };
It successfully compiles and executes with gcc 4.5 and clang 2.9, but will it always be true?
Printing this table give... | In the C99 standard, it seems that the order of initialization of the members is guaranteed:
§6.7.8/17: Each brace-enclosed initializer list has an associated current object. When no designations are present, subobjects of the current object are initialized in order according to the type of the current object: array e... |
7,378,605 | 7,378,664 | C++ Windows process ID in binary | I would like to write in C++ on Windows the prcoess ID of the program (by the program itself) in a file (binary is preferred).
I saw the use of the function: GetProcessId, but i didn't manage to work with it.
1) How to use it?
2) how to tranfer the value into binary and write to the file?
Thanks
| You can use GetCurrentProcessId() to get the process id of the current process. Then you can use ultoa to convert that number to a string using base 2 (and a buffer of size sizeof(DWORD) * 8 + 1), then you can use ofstream or fwrite to write it to a file.
Example:
DWORD id = GetCurrentProcessId();
char buf[sizeof(DWOR... |
7,378,675 | 7,381,380 | What's a good and safe language for drawing intensive particle systems over a long period of time? | Another one of my rather ambiguous question today, sorry.
Currently I have written some half decent software that has a 'roll your own' RESTful client, which pulls data from twitter. This data is then visualized with a number of particle systems using Open FrameWorks (a framework that works with c++).
My plans for this... | Haskell's (or more specifically GHC's) number crunching speed is approaching that of C++ but it's a little way behind. However, it's certainly not terrible, and Haskell's advantages in parallelism may become important. That is, if you write it in straight Haskell first, there's a good chance that it'll be easy to refac... |
7,378,902 | 7,378,958 | How to efficiently remove double quotes from std::string if they exist | This question risks being a duplicate e.g. remove double quotes from a string in c++
but none of the asnwers that I saw addresses my question
I have a list of strings, some of which are double quoted and some aren't, Quotes are always at beginning and end
std::vector<std::string> words = boost::assign::list_of("words"... | It would probably be fast to do a check:
for (auto i = words.begin(); i != words.end(); ++i)
if (*(i->begin()) == '"')
if (*(i->rbegin()) == '"')
*i = i->substr(1, i->length() - 2);
else
*i = i->substr(1, i->length() - 1);
else if (*(i->rbegin()) == '"')
*i = i->s... |
7,379,090 | 7,379,150 | How to call C++ functions from Python code in linux? | I want to call functions of a C++ program from Python code.
How can make C++ functions available in a Python program?
| http://www.boost.org/doc/libs/1_47_0/libs/python/doc/
Boost.Python, a C++ library which enables seamless interoperability between C++ and the Python programming language.
|
7,379,247 | 7,379,284 | Call assembly function from C++ | Added a bit more assembly on top of the function and below it to get a clearer image
00427F38 . 50 PUSH EAX
00427F39 . 8975 08 MOV DWORD PTR SS:[EBP+8],ESI
00427F3C . E8 0FFE0200 CALL Test.00457D50
00427F41 . 8B4D 08 MOV ECX,DWORD PTR SS:[EBP+8]
00427F44 . 51 PUSH ECX ... | you need to preserve ebx, as its a non-volatile register:
__declspec(naked) void stepOneWrapped(int a1, char* a2, int a3)
{
__asm{
push ebp
mov ebp, esp
push ebx
push a3
mov ebx, [a2]
mov ecx, a1
call [callAddress]
pop ebx
leave
ret
... |
7,379,334 | 7,379,360 | Different ways of Opening a file in C++ on Windows? | When using fopen or fstream, it's necessary to specify binary mode in order to prevent character conversions. On UNIX like systems this isn't usually necessary but on Windows it is.
This leads me to wonder if this is still the "natural" way to access filesystem data on this operating system. UNIX has the "everything i... | the C run-time libraries does what the C run-time libraries does.
Windows actually has most things as a file (or should I say objects) a file name in Windows is actually an object in the global namespace \??\. If you look up the documentation for CreateFile on MSDN there's a lot more to it, especially if you go digging... |
7,379,902 | 7,379,921 | Does this get optimized out? | My assert macro is like this:
#ifdef DEBUG
#define ASSERT(x) ((void)(!(x) && assert_handler(#x, __FILE__, __LINE__) && (exit(-1), 1)))
#else
#define ASSERT(x) ((void)sizeof(x))
I thought this was more or less bulletproof but I seem to be using it a lot in the context of asserting the return value of functions which ... | The usual meaning of assert is to be optimized out, so it might be better to stick to those semantics and do
#else
#define ASSERT(x)
#endif
If you insist on it not being optimized out, why not just do
#else
#define ASSERT(x) ((void)(x))
#endif
?
|
7,380,027 | 7,380,065 | How to print a c++ object members using GDB from an address if the object's class type is like A::B | From this link
gdb interpret memory address as an object
we know that, if an object of class type A is at a specific address such as 0x6cf010, then we can use:
(gdb) p *(A *) 0x6cf010
to print the member elements of this object.
However, this seems doesn't work when c++ namespace is involved. That is, if the object... | Works for me:
g++ -g test.cpp -o test
gdb test
(gdb) break main
(gdb) r
Breakpoint 1, main () at test.cpp:22
22 A::B *p = new A::B(100);
(gdb) n
24 p->print();
(gdb) n
m_a is 100
26 int *q = 0;
(gdb) p p
$1 = (A::B *) 0x602010
(gdb) p (A::B *) 0x602010
$2 = (A::B *) 0x602010
(gdb) p *((A::B *) 0x602010... |
7,380,193 | 7,380,291 | STL for_each with multiple return values and/or virtual base class functor | I trying to convert some loops in my code to use the for_each functionality of the STL. Currently, I calculate and accumulate two separate values over the same set of data, requiring me to loop over the data twice. In the interest of speed, I want to loop once and accumulate both values. Using for_each was suggested... | Here is an example of using a functor to perform two accumulations in parallel.
struct MyFunctor
{
// Initialise accumulators to zero
MyFunctor() : acc_A(0), acc_B(0) {}
// for_each calls operator() for each container element
void operator() (const T &x)
{
acc_A += x.foo();
acc_B +=... |
7,380,227 | 7,380,369 | C++ How to control Image Base of LoadLibrary API | After Rebasing the main program very high up in it's own imagebase.
How do I guarantee that the dll that gets loaded will load in 0x400000
dllImageBase = LoadLibrary("test.dll");
printf("imagebase = 0x%x", dllImageBase);
I always get 0x460000 instead of 0x400000
I need my dll first instruction to start from 0x401000, ... | You are going to have to disable Address Space Layout Randomization to get the DLL loaded where you want it. A feature designed to stop you from what you are trying to do. /DYNAMICBASE linker option. Loading at 0x400000 worked when I tried it.
|
7,380,376 | 7,380,388 | "Exploring C++ book" compiler setup | I just got this book "Exploring C++" and I'm on my first lesson. I've been doing C# for a couple years as a hobby so i though why not give C++ a try.
In the book it says i need to setup my compiler to use standard C++. I am using visual studio 2010 so i did. http://msdn.microsoft.com/en-us/library/ms235629.aspx
but whe... | not is an "alternative token" for the boolean operator !.
Perhaps your compiler doesn't support it.
Try this instead:
if (!in)
Indeed, here's exactly the same issue on another site.
VC compiler doesn't by default recognize alternative tokens (they are exceedingly rare nowadays), but I believe this support may be tur... |
7,380,450 | 7,380,491 | Why isn't my assignment operator getting called? | I'm confused... why isn't my assignment operator getting called here?
template<typename This>
struct mybase
{
This& operator =(const This &other)
{
__debugbreak(); // The debugger should break here, but doesn't.
return static_cast<This &>(*this):
}
};
struct myderived : mybase<myderived>
{... | mybase::operator= is hidden by the automatically generated copy assignment operator myderived::operator=.
You can use a using declaration to make the base class operator visible in the derived class.
EDIT: added example per request:
template<typename This>
struct mybase
{
This& operator =(const This &other)
{
... |
7,380,558 | 7,381,088 | MySQL connector c++ linux | I am trying use the mysql connector in c++ in ubuntu.
It appears that it requires the boost library. I did not want to bring in the boost library as it is large and this is running on a somewhat memory limited embedded platform. is there any way to include only parts of the boost library, and if so, how would I find ou... | I have used the MySQL Connector for C++ on Linux (select "Linux - Generic" in the drop-down box). It does not require Boost. You may want to try this one in lieu of the one you're using.
|
7,380,589 | 7,380,663 | OpenGl changing the unit of measure for coordinate system | I'm learning OpenGL using the newest blue book, and I was hoping to get a point of clarification. The book says you can use any system of measurement for the coordinate system, however when doing 3d perspective programming, the world coordinates are +1/-1.
I guess where I am a little confused is lets say I want to use ... | I think the author is referring to normalized coordinates (device coordinates) that appear after the perspective divide.
Typically when you actually manipulate objects in OpenGL you use standard world coordinates which are not limited to -1/+1. These world coordinates can be anything you like and are translated into... |
7,380,729 | 7,380,766 | Warning for const in typedef | When I was compiling a C++ program using icc 11, it gave this warning:
warning #21: type qualifiers are meaningless in this declaration
typedef const direction_vector_ref_t direction_vector_cref_t;
It is saying const just meaningless. I am curious about this since if this typedef expands it will turn into const arr... | Are you sure? Try:
array<double, 3> a;
direction_vector_cref_t b = a;
b[0] = 1.0;
The issue here, is that when you use a typedef, it conceptually adds parentheses around the type, so you are conceptually using const (array<double, 3>&) as opposed to (const array<double, 3>)&, so you are not actually making the referen... |
7,380,888 | 7,380,910 | Object with abstract member(without pointers) | I have the following class,
class Simulation {
public:
btDefaultCollisionConfiguration collisionConfiguration;
btBroadphaseInterface broadphase;
btSequentialImpulseConstraintSolver solver;
btDynamicsWorld dynamicsWorld;
Simulation() {
broadphase = btCollisionDispatcher(&collisionConfiguration);
}
}
an... | Yeah, you can only have pointers or references to abstract classes because you can't instantiate an abstract class because, by definition, it has an "incomplete" definition (not to be taken literally). It's just an interface.
If you want to avoid pointers, you can use references, like this:
class Simulation {
public:
... |
7,381,285 | 7,381,413 | Where to free the memory allocated in functions overloading operator | I was trying to learn basic C++ operator overloading concepts. I have a class mystring and related code as shown below. In functions used to overload '+' operator, where can I free the memory to avoid memory leaks.
#include <iostream>
class mystring
{
char *ptr;
public:
mystring(char *str = "")
{
... | Simple fix:
mystring operator +(mystring s)
{
char *str = new char[strlen(ptr) + strlen(s.ptr) + 1];//where should this memory be freed
strcpy(str,ptr);
strcat(str,s.ptr);
mystring v1(str);
delete[] str;
return v1
}
Or have a private constructor
MyStr(char *str, bool d... |
7,381,366 | 7,388,476 | adding/mixing colors in HSV Space | I've been trying to get a visualisation going for a few days.
I'm generating a diffraction image and want to color it depending on the wavelength of light.
The easiest way to get the right color was by using the HSV space with H varying with the wavelength and S,V set to 1.0
Alas, I can't find a formula/algorithm/way t... | Honestly, I'd convert the RGB, average the components and convert back to HSV.
It's not the most efficient way, but you'll presumably have or need RGB<->HSV code and the RGB calculation is likely to be much simpler.
|
7,381,599 | 7,381,614 | C++ static variable and function errors |
Possible Duplicate:
What does it mean to have an undefined reference to a static member?
I have a static class as follows:
.h file
class c1 {
public:
static int disconnect();
private:
static bool isConnected;
};
.cpp file
#include c1.h
int c1::disconnect()
{
c1::isConnected = false;
... | You have to provide an actual object instance for the static class members. Add the following to your .cpp file:
bool c1::isConnected;
To initialize it to a specific value, add an initializer:
bool c1::isConnected = false;
(By the way, classes in C++ cannot be static. Classes are just types. Only class members can ... |
7,381,757 | 7,989,043 | C++ terminate called without an active exception | I am getting a C++ error with threading:
terminate called without an active exception
Aborted
Here is the code:
#include <queue>
#include <thread>
#include <mutex>
#include <condition_variable>
template<typename TYPE>
class blocking_stream
{
public:
blocking_stream(size_t max_buffer_size_)
: max_buffer_... | When a thread object goes out of scope and it is in joinable state, the program is terminated. The Standard Committee had two other options for the destructor of a joinable thread. It could quietly join -- but join might never return if the thread is stuck. Or it could detach the thread (a detached thread is not joinab... |
7,381,887 | 7,381,919 | Can I use the type of "this" as a template argument (inside a macro)? | I currently have this:
#define THIS(T) (boost::static_pointer_cast<T>(shared_from_this()))
The macro is used in a method like this:
void Derived::run() {
do_something_with_a_shared_ptr(THIS(Derived));
}
That's all well and good, but I'd like to eliminate (Derived) and have:
void Derived::run() {
do_something_... | Not exactly an answer to your question, but have you considered using a member function instead of a macro? I usually do something like:
boost::shared_ptr< Derived > shared_this()
{
return boost::static_pointer_cast<Derived>(shared_from_this());
}
boost::shared_ptr< Derived const > shared_this() const
{
retur... |
7,382,014 | 7,382,656 | C++ Why does this specific situation cause a symbol linking error? | I'm working on an application where there's a 'core' and multiple plugins. I'm using Qt on Linux, and I use Qt's plugin loader system. Plugins are created as shared object files (*.so) and loaded dynamically. If I link to a library with a plugin, and that library links to additional libraries, I often get an 'undefined... | You have to keep in mind that a static library is nothing more than a collection of object files packaged together into a single file. If your plugin needs LibA, and LibA needs LibB and LibC, then when you link your plugin you have to tell the linker where LibA, LibB and LibC are.
If you work with dynamic libraries it ... |
7,382,076 | 7,382,151 | OpenGL Skybox Not Rendering Sides Correctly | I am pretty new to OpenGL and have run into a problem trying to render a skybox.
This picture illustrates the issue fairly well.
The sides of the skybox do not show up, and when I view an edge (like in the pic),
it just looks like the images are rendered right next to each other, instead of as
different sides of a cube... | Your textures need to form a seamless join across cube edges. In the screenshot you've supplied, these images don't form a seamless join (look at the sky).
Also check your projection matrix - are you setting a perspective transform?
To set up a perspective projection (the most common for 3D apps):
glMatrixMode(GL_PROJE... |
7,382,090 | 7,382,107 | C++ vector push_back | What is the proper way of pushing a new object element onto a std::vector? I want the data to be allocated in the vector. Will this copy the object newradio into the vector and then get rid of newradio when it goes out of scope (e.g. out of the stack)?
vector<Radio> m_radios;
Radio newradio(radioNum);
m_radios.push_bac... | std::vector manages its own memory. That means that, when the destructor of a vector is invoked the memory held by the vector is released. std::vector also invokes an object's destructor when it is removed (through erase, pop_back, clear or the vector's destructor).
When you do this:
Radio newradio(radioNum);
m_radios.... |
7,382,412 | 7,382,426 | holding 2^63 -1 in long long | I ran the following two pieces of code on Windows XP (Code:Block, MinGW), and Ubuntu (11.04, G++)
I have trouble running the following code
#include <iostream>
using namespace std;
int main(){
long long a = 9223372036854775807;
cout << a;
return 0;
}
That number is 2^63 -1. But I will get an error ... | long long a = 9223372036854775807LL;
The LL makes the literal a long long literal. Otherwise the literal defaults to being a long literal and then is casted over to a long long before being stored in a.
|
7,382,644 | 7,382,864 | How to efficiently copy a std::vector<char> to a std::string | This question is a flip side of this How to efficiently copy a std::string into a vector
I typically copy the vector this way ( null terminated string )
std::string s((char*)&v[0]);
or ( if the string has already been declared ) like this
s = (char*)&v[0];
It gets the job done but perhaps there are better ways.
EDIT... | std::string s( &v[ 0 ] );
generates less than half the number of lines of assembly code in Visual C++ 2005 as
std::string s( v.begin(), v.end() );
|
7,382,711 | 7,382,730 | Why is the C++ scope resolution operator ::? | This is one of the few questions I didn't find an answer to in Design and Evolution of C++ by Stroustroup. Why is the C++ scope resolution operator ::, as opposed to just :?
I'm guessing it's because : is already used to indicate the start of an initialization list in a constructor. Does anyone else agree, disagree, ... | It would create an ambiguity with goto labels, for one.
foo:bar; // is foo a label or a namespace?
|
7,382,761 | 7,382,794 | Why creating an lvalue is one of the benefits of returning a reference in C++? | I am reading some C++ text at the address: https://cs.senecac.on.ca/~chris.szalwinski/archives/oop244.071/content/custo_p.html.
In the section RETURNING A REFERENCE, the author wrote:
"
Returning a reference from a function has two intrinsic benefits:
efficiency
creates an lvalue
"
I can understand the first benefit... | That simply means that you can assign something to the result of the function. Consider this example:
int& foo() {
static int x;
return x;
}
void bar() {
foo() = 42;
}
Instead of int, this works with class objects as well, of course. The point is that by returning a reference to x the caller can directly assign... |
7,382,906 | 7,383,682 | Can't assign requested address, C++ UDP sockets | The following code is from http://digitalpbk.blogspot.com/2007/10/unix-networking-sockets-udp-transmitter.html, It runs fine on localhost but when I change it to my ip it gives the error
bind(): Can't assign requested address
I have been searching for a solution for a few hours so any help would be great
int main(void)... | Most likely you're changing it to the IP that people see you as, not the IP you see yourself as. (Assuming windows from the parameters the functions take) Go to start -> control panel -> (Network & Internet ->) network connection/change network adapter settings and then right click on your network adapter and select st... |
7,382,949 | 7,382,973 | push_back() in a 2d vector, what is the right syntax? | I have defied a variable type as follows:
typedef unsigned int color[3];
I then created a vector of that type:
vector<color> RGB;
Now, say I want to push back a new element to this vector. What is the right syntax? My g++ won't let me do something like:
color temp = {255, 255, 255};
RGB.push_back(temp);
Which I thou... | You can't use raw arrays as types for any of the standard containers.
The types must be assignable (they have either an implicit or explicit operator =) and constructable (they have either implicit or explicit default and copy constructors).
You could wrap your array type in a struct to allow use with the standard cont... |
7,383,103 | 7,383,120 | Use cout/cin when overloading IO Operators in C++? | I am testing some C++ code related to overloading IO operators. The code as follows:
class Student {
private:
int no;
public:
Student(int n)
{
this->no = n;
}
int getNo() const {
return this->no;
}
friend istream& operator>>(istream& is, Student& s);
friend os... | The difference is obvious, is/os are input/output streams while cin/cout are the standard input/output streams. cin/cout are instances of i/o streams, not synonyms.
The point being, there are streams other than standard input/output, such as files, string streams, and whatever custom implementation you can think of. If... |
7,383,341 | 7,383,347 | difference between getch() and (*getch)() | I want to know the difference between these two statements....
ch=getch();
ch=(*getch)();
both statements return the same vale in "ch". I am possibly wrong but I think the second statement is used when we want to speed up the execution of the program.
| They do exactly the same thing.
There's no difference whatsoever.
|
7,383,572 | 7,383,639 | c++ shared_ptr of stack object | I have been learning managed pointers lately and ran into the following scenario.
I am implementing a model/controller class for a game view. My view, will render things in the model. Pretty straight forward. In my main function, I instantiate all three like this:
RenderModel m;
m.AddItem(rect); // rect gets added just... |
how do I dictate that a parameter was not allocated on the stack?
Yes, require the caller to provide a std::shared_ptr<RenderModel>. If the caller misconstructs the std::shared_ptr, that's the caller's problem, not yours.
If you intend for a RenderView to be the sole owner of a particular RenderModel, consider havin... |
7,383,683 | 7,383,790 | Get audio samples from byte array | How to get data samples from QAudioInput
I found in this examples code from audioinput example code
void InputTest::readMore()
{
if(!m_audioInput)
return;
qint64 len = m_audioInput->bytesReady();
if(len > 4096)
len = 4096;
qint64 l = m_input->read(m_buffer.data(), len);
if(l > 0... | This page indicates read() is expecting a char* to store the data in. If you have set up the format of the audio device properly the data will indeed be 'segmented' as shorts in the char array and you can simply cast the char* to a short* before passing it to your library.
|
7,383,840 | 7,383,998 | How does the compiler internally solve the diamond problem in C++? | We know that we can solve the diamond problem using virtual inheritance.
For example:
class Animal // base class
{
int weight;
public:
int getWeight() { return weight;};
};
class Tiger : public Animal { /* ... */ };
class Lion : public Animal { /* ... */ };
class Liger : public Tiger, ... | The compiler builds tables that list all the members of every class, and also has links that allow it to go up and down the inheritance chain for any class.
When it needs to locate a member variable (weight in your example) the compiler starts from the actual class, in your case Liger. It won't find a weight member the... |
7,384,021 | 7,384,263 | BST implementations in STL |
C++ STL "set" and "map" support logarthmic worst case time for insert,
erase, and find operations. Consequently underlying implementation is
Binary search tree. An important issue in implementing set and map is
providing support for iterator class. Ofcourse, internally the
iterator maintains a pointer to the "... |
There is nothing in the C++ specification that requires the use of a binary tree. Because of this, ++ and -- are defined in terms of the sequence of elements. map and set store an ordered sequence of elements. Therefore, ++ will go to the next element, and -- will go to the previous element. The next and previous elem... |
7,384,160 | 7,384,209 | How to create an object of class defined inside namespace in c++ | namespace t {
class A {};
}
How can create an object of class A?
EDIT :
namespace beta {
class TESSDLL_API TessBaseAPI
{
public:
TessBaseAPI();
virtual ~TessBaseAPI();
}
}
This is the class defined inside beta namespace . Now how do i call the constructor? is
tess = new bet... | Either
namespace t
{
A a;
}
or
t::A a;
In the first case a lives inside namespace t (in fact its full name is ::t::a).
In the second case a is global.
(note: your class A{} is missing a ; after })
|
7,384,531 | 7,399,720 | Pollable signalling between threads | I'm working on a project, where a primary server thread needs to dispatch events to a series of worker threads. The work that goes on in the worker threads relies on polling (ie. epoll or kqueue depending on the UNIX system in question) with timeouts on these operations needing to be handles. This means, that a normal ... | Jan Hudec's answer is correct, although I wouldn't recommend using signals for a few reasons:
Older versions of glibc emulated pselect and ppoll in a non-atomic fashion, making them basically worthless. Even when you used the mask correctly, signals could get "lost" between the pthread_sigprocmask and select calls, me... |
7,384,585 | 7,384,707 | A reference pages for the latest version of c++ | For c++03, there are next reference pages :
cplusplus
IBM pages for c++
MSDN c++ reference pages
I used cplusplus as reference pages as a reference for c++ classes and functions (I am aware it is has errors, but is quite ok).
However, all these pages are for c++03.
Are there similar pages for c++11?
| I usually refer to the latest
standard draft
You can also check cppreference.com, but it is still incomplete.
|
7,384,956 | 7,384,979 | Is there a file pointer (FILE*) that points to nothing? | For some reasons I need a file pointer (FILE*) that points to nothing. It means I can pass it to fprintf function and fprintf ignore the file pointer.
for example:
void my_function()
{
FILE* nothing = NULL; // NULL is not correct.
int n = fprintf(nothing, "PI = %f", 3.14); // Note: When nothing = NULL, error ocured... | No.
Your code will cause a run-time exception. You can use /dev/null for example, if you're running on an OS that supports it, but there's nothing like that built-in in C++.
|
7,385,040 | 7,385,097 | C++ Memory Mapped File Implementation | I have no problems implementing the memory mapped file. The question is. Assuming this returns a valid memory view.
void* pBuf = MapViewOfFile(hMapFile,
FILE_MAP_WRITE,
0,
0,
0);
Do i have alternatives to using memcpy to give data to it? for instance can i tel... | You can use the placement new operator or you can cast the address to a structure or class you want to use. The advantage of placement new is that the constructor of the class will be called. If you use from then on that pointer you don't need to copy the data but read and write directly to it.
|
7,385,240 | 7,385,506 | How to read last 10 line of text file using CStdioFile | I would like to read last 10 lines of a big text file.
Normally I loop through the file and get the last 10 lines.
Please kindly tell me, are there other ways to read the last lines quicker.
Thanks.
| You can get the file's length in bytes with (CStdioFile::GetLength) (inherited from CFile):
http://msdn.microsoft.com/en-US/library/b569d0t4(v=VS.80).aspx
And you can use CStdioFile::Seek to jump to an arbitrary offset:
http://msdn.microsoft.com/en-US/library/8c5ccz0x(v=VS.80).aspx
If the line length is fixed, it's a p... |
7,385,250 | 7,385,325 | Doxygen not listing nested namespaces | I have updated our c++ class comments to doxygen format and they look nice... but the namespaces list/tab is not at all useful. We have a parent namespace e.g john and then sub-namespaces for each library or functional area e.g john::graphics, john::sound, etc.
Doxygen is only listing a single namespace: john.
Do I hav... | In general, you have to document anything for Doxygen to decide that it's important. Namespaces in included. But you don't have to document them particularly well; just a brief notation of what they're for is sufficient for Doxygen to document them.
|
7,385,279 | 7,385,296 | php how to add a reference | i would like to ask how to convert: method(Class1::Class2 &class); in php?
what should i write: me->method(????)
hx. appreciate
I am working in c__/ubuntu.
| The same way:
function method(&$variable)
However, if &class is an object, it's not necessary - since PHP 5, objects are automatically passed as reference. a kind of references in themselves, so this isn't necessary.
|
7,385,328 | 7,385,568 | Array write-protected by C# virtual machine | I'm writing a C# application, and I need part of it to be in C++ for speed efficiency.
The function in C++ is exported as follow:
extern "C" __declspec(dllexport) int fastSegment(char*, int, int);
I import this function in C# as follow:
[DllImport(_dllname, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet... | The garbage collector is allowed to move managed data. The native code is not able to detect this, so it is possible that it writes to the wrong memory address. But you can tell the .NET runtime not to move your array. E.g. with the GCHandle class:
GCHandle handle = GCHandle.Alloc(image, GCHandleType.Pinned);
try
{
... |
7,385,626 | 8,403,838 | XmlSpy: memory leaks in auto-generated xml parser | I generated a C++ xml parser using Altovas XmlSpy 2011R3 SP1. The parser is based on Xerces 3.1 and used as a dynamic link library with MFC support.
I'm getting memory leaks inside xerces just running the example generated with the altova parser that loads a xml from file and does nothing else with it.
Leaks are detec... | This is an confirmed error in the example code provided by Altova. To fix the leaks make sure to always call DestroyDocument to free all Memory.
|
7,385,658 | 7,385,688 | new and delete char* causes exception | I have the following code, but it causes an exception. Without itoa "games" I don't think there's a problem. TextOutA is because I use winapi.
char* p1 = new char[2];
itoa(10,p1,10);
TextOutA(hDC,5, currenty,p1,2);
delete[] p1;
| Your stringbuffer is too short
itoa overruns the buffer capacity in writing the null termination character.
char* p1 = new char[3];
itoa(10,p1,10);
TextOutA(hDC,5, currenty,p1,2);
delete[] p1;
I suggest you make the buffer big enough to accomodate the full integer range.
Edit Just in case, elaborating on the string s... |
7,385,717 | 7,385,974 | Simple Property System | I have run into a small design predicament. It's not really a "problem" per se, it's just bothering me that I cannot find a cleaner solution :) and I was hoping some of you might have some good ideas or alternative solutions.
Say I have some pieces of data that can arrive on a communications channel (serial/IP, e.t.c) ... | I'd write a Property class that stores a collection of data chunks. Each chunk is either a Boost.Variant or some type of union, or a pointer to an an object that implements a data chunk interface.
The class could be initialized like
Property p;
p.addInt(xI).addFloat(xF).addShort(xS);
or like
Property p = { IntVal(xI),... |
7,386,210 | 7,426,350 | convert OpenCV 2 vector<Point2i> to vector<Point2f> | The OpenCV 2 contour finder returns a vector<Point2i>, but sometimes you want to use these with a function that requires a vector<Point2f>. What is the fastest, most elegant way to convert?
Here are some ideas. A very general conversion function for anything that can be converted to a Mat:
template <class SrcType, clas... | Assuming src and dst are vectors, in OpenCV 2.x you can say:
cv::Mat(src).copyTo(dst);
And in OpenCV 2.3.x you can say:
cv::Mat(src).convertTo(dst, cv::Mat(dst).type());
Note: type() is a function of the Mat and not of the std::vector class. Therefore, you cannot call dst.type(). If you create a Mat instance using ... |
7,386,496 | 7,386,539 | Virtual unnecessary for protected functions | Say class B derives from class A. That both declare f(). f is protected. Hence f will only be called inside A and inside B. Does f() need to be declared virtual?
Or rather: say C derives from B derives from A. B and A declare protected non-virtual f(). Will a call to f() in C and B resolve to B::f() and in A to A::f()?... | Declaring your protected method virtual is necessary when you want polymorphic behaviour (an example to this is the Template Method pattern), and is to be avoided when you don't. However, in the latter case you should not shadow the function with another function having the same signature in the subclass, otherwise you... |
7,386,511 | 7,388,720 | Allocate the size of memory mapped files dynamically in Windows Mobile | I am trying to find a way to allocate memory dynamically for memory mapped files that are shared between different processes. My design is as follows: In Windows mobile, I am writing a Display Thread that handles the display part from different processes using shared memory. The plan is to create a memory mapped file t... | Don't use a file, there's no value in having this data written to disk. Pass INVALID_HANDLE_VALUE to CreateFileMapping so that the memory is backed by the paging file and you can set any size you need.
|
7,386,536 | 7,388,197 | Is there a good test for C++ optimizing compilers? | I'm evaluating Visual C++ 10 optimizing compiler on trivial code samples so see how good the machine code emitted and I'm out of creative usecases so far.
Is there some sample codebase that is typically used to evaluate how good an optimizing C++ compiler is?
| The only valid benchmark is one that simulates the type of code you're developing. Optimizers react differently to different applications and different coding styles, and the only one that really counts is the code that you are going to be compiling with the compiler.
|
7,386,628 | 7,386,860 | Temporaries lifetime in N3290 C++ draft | A point from N3290 C++ draft, § 12.2, 5th point, line 10.
The second context is when a reference is bound to a temporary. The
temporary to which the reference is bound or the temporary that is the
complete object of a subobject to which the reference is bound
persists for the lifetime of the reference except:
... | Temporaies in general last only to the end of the expression that they were created in:
#include <complex>
void func()
{
std::complex<int> a; // Real variable last until the end of scope.
a = std::complex<int>(1,2) + std::complex<int>(3,4);
// ^^^^^^^^^^^^^^^^^^^^^^ Creates a temporary object
//... |
7,387,354 | 7,388,958 | Is there any C++ IDE that supports TextMate-Like Snippets? | I'm currently using Code::Blocks for develop C++ programs.
But I miss the nice bundles from SublimeText or Gedit with Plugins.
Is there any C++ IDE that allows using Bundles ? Or any Code::Block plugin for that ?
Thanks.
edit: A snippet is when you type "class", and press tab for example: that will create for you the c... | Though not an IDE, Vim has snipMate which I use constantly for my code. There's also snippetsemu which I have not tried but have heard good things about.
|
7,387,683 | 7,387,803 | Regular expressions in Visual Studio | I want to find all lines matching a word containing 'if' in a bunch of C++ source files in Visual Studio, so I need to filter out the if statements as well as the #if preprocessor statements.
The regular expression I'm trying to use is the following: [^#]*if[^\s]+
But the results I get include all the if statement and ... | \s isn't the VS shortcut for whitespace, :b is (space or tab). That's covered in the docs page you linked to.
|
7,387,760 | 7,392,092 | c++ classes inside php extension | I would like to ask if it's importat the name for _object_handlers, php_minit_function when creating an extension:
I have the following:
[test.h]
public:
class A
{
public:
A();a
class B{
public:
B();
class Dat
{
//variables
};
//methods
bool first_method(A::B::dat &d);
};
};
I need some help when creating the php_hea... | you have to use C calling conventions for extension functions. So you should wrap them in a extern "C" {} declaration so PHP can call them.
Also mind that PHP_METHOD(foo, bar) becomes zim_foo_bar, so your PHP_METHOD(A::b, set) becomes zim_A::b_set, which explains your error message.
|
7,387,776 | 7,387,825 | How to catch event from CLR on C++ | I'm running simple dialog on CLR where I fill some textBoxes and press push, So but I need to know when I pressed push.
Here is how I run dialog :
void CFloBossOPCDlg::OnBnClickedButton3()
{
NewBoi ^ nb = gcnew NewBoi();
nb->Show();
I can't declare nb as global variable and even I can't declare nb as part of... | You can use gcroot to declare handles in native types.
http://msdn.microsoft.com/en-us/library/481fa11f(v=vs.80).aspx
|
7,387,846 | 7,404,354 | Updating itk image in Qt user interface | I have a problem that I would like to tell you because is about some days that I don’t have new ideas.
I have an image pointed with a double* pointer, and I want to translate it into itk::smartpointer for updating the user graphic interface, for this purpose I made this method :
void prueba_r01::double2itk( double *im_... | ITK has built-in mechanisms for this, with some considerable safety advantages. Also: they can be used in a pipeline like any image source, and because they use your existing array they will be considerably faster (I think) than looping over the indices.
http://www.itk.org/Doxygen/html/classitk_1_1ImportImageFilter.htm... |
7,388,104 | 7,388,497 | How to set breakpoint by function name inside anonymous namespace in Visual Studio? | I have the following code:
namespace
{
void Foo()
{
}
}
namespace Bar
{
void Foo()
{
}
}
int main()
{
Foo();
Bar::Foo();
return 0;
}
I want to put breakpoint on Foo() inside anonymous namespace by name (Ctrl+B key binding). I can do it for function inside named namespace Bar with... | I encountered a similar problem a long time ago (Debugging data in 'anynomous namespaces' (C++)). I wanted to look at the value of a data member in an unnamed namespace, but I couldn't get this done.
Finally, somebody pointed me to http://msdn.microsoft.com/en-us/library/0888kc6a%28VS.80%29.aspx. Maybe you can get th... |
7,388,388 | 7,388,599 | boost condition needs volatile variables | Hy,
I have started working with threads in C++ (boost threads),
and I have found my self in the following situation:
boost::mutex::scoped_lock lk(monitor);
while (buffered == 0) {
buffer_not_empty.wait(lk);
}
And I was wandering if the int variable buffered should be volatile.
I would say that it should, to preve... | You need not mess with volatile. volatile has absolutely nothing to do with multithreading. Even if the compiler doesn't optimize things away to the loop you mention somehow, your CPU might make the same optimization, and volatile does not affect the CPU.
wait should contain the necessary memory barrier instructions re... |
7,388,410 | 7,388,496 | How to cross-platform converting char* to long long (64-bit)? | How can I convert a char* string to long long (64-bit) integer?
I use MSVC and GCC compilers and my platforms are Windows, Linux and MAC OS.
Thanks.
| Use strtoull for unsigned long long or strtoll for signed long long. On any Unix (Linux, Mac OS X), type man strtoull or man strtoll to get its description. Since both are part of the C99 standard they should be available on any system that supports C. The Linux man pages also have examples on how to use them.
|
7,388,450 | 7,389,603 | combining two constructors that copy and move | Currently, one of my toy class templates has two constructors that look very similar:
optional(const T& x)
{
construct(x);
}
optional(T&& x)
{
construct(std::move(x));
}
Can I combine them into a single constructor template, or will this change the semantics somehow?
template<typename U>
optional(U&& x)
{
... | It changes the way traits such as std::is_constructible and std::is_convertible interact with optional. For example given:
class A {};
int main()
{
std::cout << std::is_constructible<optional<A>, int>::value << '\n';
};
Your original code would print out:
0
But your new code will print out:
1
If this is undesi... |
7,388,758 | 7,392,673 | Optimization Headache - removing if's from Look Up Table | I'm trying to optimize the following piece of code, which is a bottleneck in my application.
What it does: It takes the double values value1 and value2 and tries to find the maximum including a correctional factor. If the difference between both values is greater than 5.0 (the LUT is scaled by factor 10), I can just ta... | A couple of minutes of playing with Excel produces an approximation equation that looks like it might have the accuracy you need, so you can do away with the lookup table altogether. You still need one condition to make sure the parameters to the equation remain within the range that it was optimized for.
double diff =... |
7,388,768 | 7,388,802 | [] operator for std::list? | I'm in a situation where I cannot use a vector because I use &element[x] then add more items so the pointer is invalidated. The problem is that std::list does not seem to overload the operator [] nor provide an at() method. Therefore the only way I see I could simulate at() is by using an iterator. Is there however a b... | You should reconsider your design probably.
Trying to emulate operator[] or at for std::list would lead to performance disaster: these operations would take O(N) and not O(1) time as std::list::iterator is Bidirectional iterator, not Random Access iterator. So if you now iterate through container and call[] or at for e... |
7,388,785 | 7,389,667 | How to build a string with UTF characters in C++ (QT framework) | I am trying to construct a string (QString) made up of 'bullets' (black small circle, U+2022).
Anyone know how I'd do this?
Thanks in advance,
Wes
eg: "* * * * * *" but bullets instead of asterisks
| You can create a single black bullet by using:
QString::fromUtf8( "\u2022" );
You can string some of those together to get what you want.
|
7,388,805 | 7,388,832 | Does clang already support C++11? | I would like to use std::array, std::regex and other things that are new in C++11.
Does clang already support C++11?
| Yes but not everything. Check out this status page; it's updated very frequently. It's the current source code (work in progress) state, not the last release state, so check the version in the table to be sure it corresponds to what you have.
For standard library features, checks the links at the end of the page, depen... |
7,388,889 | 7,388,915 | what's a variable with & -> double& | So I have a class made in c++ and need to convert it into vb.net but I got problem converting a certain part of a function.
void deg_min_sec2decimal(double deg, double min, double sec, double& dec_deg)
{
dec_deg = (deg+min/60.0+sec/3600.0);
}
What type of variable is "double&", I know a double but what's with the ... | It's a reference. That means that whatever you set the value to inside the function, the original variable that was passed in from outside will have that value.
You can convert this to VB by using ByRef or making the function return the result of that expression instead of taking the double&, and setting the variable y... |
7,388,907 | 7,389,094 | Multiple files in one | I'm trying to create my own file format. I want to store image file
and some text description in that file.
File format will be something like that:
image_file_size
image_data
desctiption_file_size
description_data
But without '\n' symbols.
For that purpose i'm using std::ios::binary. Here is some code,
describes that... | Since you are storing and reading binary data everywhere, you should open and create all files in binary mode.
In the write part:
std::ifstream input_image(m_image_file_path.toUtf8().data(), std::ios::in | std::ios::binary);
In the read part:
std::fstream m_in(m_file_path.toUtf8().data(), std::ios::in | std::ios::bina... |
7,389,141 | 7,390,402 | Testing iterative code using mocks - does it make sense, how? | I want to test an algorithm using mocks. The algorithm - in the current implementation - iterates over a container class in multiple passes and set()s and get()s values from it. The test's purpose is to verify the final result, stored in the container. The final value depends on values read and written in between the p... | I would say that if the container is slow in some way or it has side-effects that mean you cannot read its values without disturbing it, then you should use a mock.
Otherwise, using a mock is a waste of time. Would you use a mocked version of std::vector? I wouldn't; it would be silly.
With your unit testing, if you ca... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.