c++

Which side (left or right) of && (and) operator evaluated in C++

Which order is the and && operator evaluated For example the following code if (int alpha = value1-value2 && alpha > 0.001) //do something threw an exception that alpha is being used without being initiated. I thought the expression left of the && would always initiate the value of alpha first, but it seems I may be wrong Any id...

Strange behaviour of ldr [pc, #value]

Hi, I was debugging some c++ code (WinCE 6 on ARM platform), and i find some behavior strange: 4277220C mov r3, #0x93, 30 42772210 str r3, [sp] 42772214 ldr r3, [pc, #0x69C] 42772218 ldr r2, [pc, #0x694] 4277221C mov r1, #0 42772220 ldr r0, [pc, #...

lua_pop vs lua_remove

currently I'm building my own script VM manager class in C++, I have no problems with any of the lua & lua C or C++ stuff, but the one section that confuses me is: when to use lua_pop and when to use lua_remove. From what I understand, lua_pop is to remove multiple values(on the stack) from the top down, eliminating data that is no lon...

Next value in std::map

I have an std::map<std::string, float> so I can do quick lookups for float values based on names, but I have a situation now where I need to find the next float value in the list as if it were sorted numerically. I cannot just use an iterator, as far as I know, since the map is key sorted. So if my set contains: std::pair<"One", 1.0> ...

Is creating an empty class purely to distinguish it from another class good practice?

I have a class CardStack. I have several classes that inherit from CardStack e.g. Cascade, Deck, Foundation etc. Foundation doesn't need to add any functionality to CardStack, but for display purposes my app needs to know which of the CardStacks are actually Foundations. Incidentally, I have no such function CardStack.Display() (I'm us...

c++ container for checking whether ordered data is in a collection

Hello, I have data that is a set of ordered ints [0] = 12345 [1] = 12346 [2] = 12454 etc. I need to check whether a value is in the collection in C++, what container will have the lowest complexity upon retrieval? In this case, the data does not grow after initiailization. In C# I would use a dictionary, in c++, I could either use a h...

Difference between member functions for a template class defined inside and outside of the class

Is there a difference between defining member functions for a template class inside the class declaration versus outside? Defined inside: template <typename T> class A { public: void method() { //... } }; Defined outside: template <typename T> class B { public: void method(); }; template <typename T> void B<...

Selecting An Embedded Language

I'm making an application that analyses one or more series of data using several different algorithms (agents). I came to the idea that each of these agents could be implemented as separate Python scripts which I run using either the Python C API or Boost.Python in my app. I'm a little worried about runtime overhead TBH, as I'm doing so...

how to set base index in ublas matrix?

hello I have searched the web but could not find an answer. how do I have set base index in the matrix, such that indexes start from values other than zero? for example: A(-3:1) // Matlab/fortran equivalent A.reindex(-3); // boost multi-array equivalent thanks ...

C++: casting to void* and back

* ---Edit - now the whole sourse* When I debug it on the end, "get" and "value" have different values! Probably, I convert to void* and back to User the wrong way? #include <db_cxx.h> #include <stdio.h> struct User{ User(){} int name; int town; User(int a){}; inline int get_index(int a){ return town; } //for another stuff }; int m...

Is it possible to use boost::foreach with std::map?

Hi, I find boost::foreach very useful as it saves me a lot of writing. For example, let's say I want to print all the elements in a list: std::list<int> numbers = { 1, 2, 3, 4 }; for (std::list<int>::iterator i = numbers.begin(); i != numbers.end(); ++i) cout << *i << " "; boost::foreach makes the code above much simplier: std::li...

Is it possible to replace the global "operator new()" everywhere?

I would like to replace the global operator new() and operator delete() (along with all of their variants) in order to do some memory management tricks. I would like all code in my application to use the custom operators (including code in my own DLLs as well as third-party DLLs). I have read things to the effect that the linker will c...

C++ Class using header and implemenation files

I've put together a simple C++ "Hello World" program to practice; unfortunately, upon compilation I get a few errors: expected ')' before fName error: prototype for 'HelloWorld::HelloWorld(std::string, std::string)' does not match any in class 'HelloWorld' Below is my code, can anyone help me understand what I'm missing/overlo...

c++ rapidxml node_iterator example?

Hi, I just started using rapidXML since it was recommended to me. Right now to iterate over multiple siblings i do this: //get the first texture node xml_node<>* texNode = rootNode->first_node("Texture"); if(texNode != 0){ string test = texNode->first_attribute("path")->value(); cout << test << endl; } //get all its sibling...

C++ boost unit test error message

I would like to write a method in my test suite as follows: void checkParams(arg1, arg2, arg3) { BOOST_REQUIRE(arg1==1); BOOST_REQUIRE(arg2==2); BOOST_REQUIRE(arg3==3); } However, I want to write something to stderr if the assert fails. For example, if the first assert fails, I want to write: checkParams failed with arguments arg1=5...

_CrtMem* and the debug heap

When I use the following code, it detects a memory leak. How can I make it not? _CrtMemState startState; _CrtMemState endState; _CrtMemState temp; _CrtMemCheckpoint(&startState); const char* foo = "I'm not leaking memory! Stop saying I am!"; _CrtMemCheckpoint(&endState); _CrtMemDifference(&temp, &startState, &endState); // Returns ...

Encrypting custom Packets in PHP/C++

I am writing a game server plugin, and writing a web interface to control it. I am considering detouring the GetPacket() function in the game server, and sending custom packets from my web panel and using GetPacket() to interpret them. My only concern is security as obviously I don't want to just send open data out. What can I read up on...

Why might trigger a breakpoint when I return TRUE from my OnCopyData?

I'm using Visual Studio to debug an ATL application. When I step over return TRUE in this code, the error occurs: BOOL CMainFrame::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) { // Code snipped from here - maybe this causes stack/heap corruption? // I have a breakpoint here, if I step over (F10), AFX trace message ...

Initializing static struct tm in a class

Hi all, I would like to use the tm struct as a static variable in a class. Spent a whole day reading and trying but it still can't work :( Would appreciate if someone could point out what I was doing wrong In my class, under Public, i have declared it as: static struct tm *dataTime; In the main.cpp, I have tried to define and initia...

Extract Digits From An Integer Without sprintf() Or Modulo (SOLVED)

The requirements of this are somewhat restrictive because of the machinery this will eventually be implemented on (a GPU). I have an unsigned integer, and I am trying to extract each individual digit. If I were doing this in C++ on normal hardware & performance weren't a major issue, I might do it like this: (Don't hate on me for this...