c++

static_cast vs const_cast

Possible Duplicate: When should static_cast, dynamic_cast and reinterpret_cast be used? what is the difference between those two casts, const_cast<const A&> and static_cast<const A&> what do You usually use in your practice? thanks in advance ...

How to append different files and extract them for verification in my code?

if i have both encrypted message and signature (let's say two different size files), i just want to append them and store in a file together but later i will use the same "only one file" to extract the files and verify in my code. in that way my code will get only one file as an input but can understand which is encrypted file and signa...

c++ how to make two vectors one with data the other points and reads only

In C++ I have 2 STL vectors A and V. A has data and is able to change it, V only points to data but reads only and can't modify it. So if these two vectors are inside a class what will be the syntax of Variables definition assigning A reference into V get_A() and get_V() will it return a reference or a pointer? Also If I have other...

Why does msvc let me do this but not gcc / g++?

In msvc, I have functions like this and it builds but in gcc it doesnt like it. void classname::a(std::string &text) { stdStringFromClass = text; } void classname::b(char *text) { a(std::string(text)); } The issue here is in the &, gcc I think is worried that since I just created that std::string, that passing by reference is...

How to link C++ program with Boost using CMake

What should my cmake file should look like for linking my program with boost library under Ubuntu? The errors show during running make: main.cpp:(.text+0x3b): undefined reference to `boost::program_options::options_description::m_default_line_length' The main file is really simple: #include <boost/program_options/options_description...

Problem Implementing Function With Existing Class Design

I've currently started on my semester project for my programming course- programming a fully autonomous driving simulator. All cars are steered through AI and the map is printed in the console. The first sheet wants us to create a couple of basic classes: FCCompact (The car), Scanner (AI), ID (terrain), and World (The map). The Scann...

Why is this loop only running once?

Why is this loop only running once? noteDatabaseItem just takes a node and fills in the data. the xml has 3 notes in it. XML: <?xml version="1.0" encoding="utf-8"?> <noteCollection> <note name="Test Note 1">This is test note 1 content!</note> <note name="Test Note 2">This is test note 2 content!</note> <note name="Test Note 3">Th...

error: cast from 'Foo*' to 'unsigned int' loses precision

I'm trying to cast a pointer to an int (or unsigned int) and no matter what I try it doesn't want to work. I've tried static_cast<intptr_t>(obj), reinterpret_cast<intptr_t>(obj), and various combinations of C style casts, intptr_t's, unsigned int's, and I'm including stdint.h. From what I've read, one of the many things I've tried shou...

Creating my object takes too long. Is it bad practice to create a ton of instances at startup to speed things up later?

I have a wizard class that gets used a lot in my program. Unfortunately, the wizard takes a while to load mostly because the GUI framework is very slow. I tried to redesign the wizard class multiple times (like making the object reusable so it only gets created once) but I always hit a brick wall somewhere. So, at this point is it a huge...

Comparing diferent algorithms

I get the following errors for this code: Error 1 : In function `_Function std::for_each(_InputIterator, _InputIterator, _Function) [with _InputIterator = std::_List_iterator, _Function = void (*)(int)]': Error 2 line 16 with the bool. int main(int argc,char *argv[]) { if (argc != 4) { cout << "Error input!"; ...

C++ #include <atlbase.h> is not found

When I compile my program it says that it can't find atlbase.h. Am I missing some SDK or something? ...

initialization of the static variables

hello everyone, I've just read that if I want to be sure about the initialization order it will be better to use some function which will turn global variable into local(but still static), my question, do I need to keep some identifier which tells me that my static object has already been created(the identifier inside function which prev...

cin.getline is skipping one line of input and taking the next

Why does cin.getline start working for the second line on the body input but break on the first? Example Program run: Enter name: Will Enter body: hello world hello again <= It accepts this one char* name = new char[100]; char* body = new char[500]; std::cout << "Enter name: "; std::cin.clear(); std::cin.ignore(std::numeric_l...

Labels in GCC inline assembly

In my ongoing experimentation with GCC inline assembly, I've run into a new problem regarding labels and inlined code. Consider the following simple jump: __asm__ ( "jmp out;" "out:;" : : ); This does nothing except jump to the out label. As is, this code compiles fine. But if you place it inside a function, and the...

How does Boost ASIO receive_from return underlying socket errors?

i.e. will the blocking version return -1 on error. Or more to the point, how do you know the call failed? does boost::asio::ip::udp::socket::receive_from() return -1 on error The normal BSD socket API receive_from call will return -1 on errors and you can look at errno for the specific error code. Does the boost version do the same?...

If I can take a normal pointer to a variable within a class, what's the point of class member pointers?

Take this code: struct mystruct { int var; mystruct() : var(0) {} }; int main() { mystruct ins; int* p = &ins.var; *p = 1; } So what are some concrete really good examples of uses for the class member pointer? int X::*p = &X::data; /* p contains offset */ X object; X *objptr = new X; int i = o...

XPATH contains(string, string) Not Working

sI have an XML file that looks like the following... <a> <b> <version>1.0</version> <c> <Module>foo.EXE</Module> </c> <c> <Module>bar.DLL</Module> </c> </b> </a> I have a COM DLL that uses MSXML2:IXMLDOMNode objects that call "selectNodes" something like... CComPtr<MSXML2::IXMLDOMNodeList> oR...

Why isn't this compiling?

I don't understand why the below code does not build: bool AguiRectangle::pointInside(const AguiPoint &p ) { if(p.getX() < x) return false; if(p.getY() < y) return false; if(p.getX() >= x + width) return false; if(p.getY() >= y + height) return false; return true; } I get this: Error 1 error C2662: 'AguiPoint...

GCC inline assembly: constraints

I'm having difficulty understanding the role constraints play in GCC inline assembly (x86). I've read the manual, which explains exactly what each constraint does. The problem is that even though I understand what each constraint does, I have very little understanding of why you would use one constraint over another, or what the implic...

c++ convert matrix into row pointer vector

vector<vector<int> > mymatrix; vector<int> *ptr_vec; How do I make the ptr_vec point to the vectors which are inside mymatrix one after another. In more details Let's say mymatrix.at(0).size() gives 10, and mymatrix.at(1).size() gives 14 ..if I go ptr_vec->at(15) it should give me the fifth member in mymatrix.at(1) hope it doesn't conf...