c++

a simple function

Hi I defined a variable name exPosition to keep the position of a node in my network and I did it in node.h file in pulic part but i can't access it normally in my code I mean in other classes(while its public) so I tried to write a function to return this variable in node .cc and followed the same structure in other classes but it gives...

swapping 2 numbers in 2 dimensional array

My question is as follows: Refer to the following array declaration in the main(): const int size = 4; int x[size][size] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 8, 7, 3}, {2, 1, 7, 1}}; Write a function SwapRows() to swap two rows of the above 2D array. For example, if the function has been called to swap the first and the second rows o...

Do We Inherit a Interface or Implements an Interface?

Well till now I knew we implement interfaces , but today some body (you know who , i guess)) told me that If I write a interface then we implement it in class , but if it is a system Interface , Let's say INotifyPropertyChanged , the we call it Class A inherits Interface INotifyPropertyChanged. Though I feel right , I am not sure and un...

How can I synchronize three threads?

My app consist of the main-process and two threads, all running concurrently and making use of three fifo-queues: The fifo-q's are Qmain, Q1 and Q2. Internally the queues each use a counter that is incremented when an item is put into the queue, and decremented when an item is 'get'ed from the queue. The processing involve two threads,...

Parse tree for SQL statements - precisely for "SELECT" statement

hi, I am writing (hand written) recursive descent parser for SQL select statement in c++, i need to know whether the parse tree created by me is correct or not. I want to check but i didn't get a good sources for sql parse trees. My way of approach is - writing a function for each production and in that function the result is adding to ...

Why reference variable inside class always taking 4 bytes irrespect of type? (on 32-bit system)

Hi, I have below code, running on 32-bit windows, visual-studio. template <class T> class Test { public: T &ref; Test(T &x) :ref(x) {} }; int main() { cout<<"sizeof Test<int> : "<<sizeof(Test<int>)<<endl; cout<<"sizeof Test<double> : "<<sizeof(Test<double>)<<endl; cout<<"sizeof Test<char> : "<<sizeof(Test<char>)<<endl; } Ou...

function calling performance

I have called snprintf a few times consecutively with different arguments. I take the time needed for each snprintf. I found that the first call to snprintf takes the longest time. After that, the time needed to call the same function decreases until it converges. What is the reason for that? I have tried with other functions and also ex...

Is there such a thing like a Printer-Markup-Language

I like to print a document. The content of the document are tables and text with different colors. Is there a lightwight printer-file-format which i can use like a template? PS, PDF, DOC files i think are to heavy to parse. May there exist some XML or YAML file format which i can Easy create (maybe with a WYSIWYG-Editor) Can parse and...

std::rel_ops functionality as a base class. Is that appropriate solution?

Hello, I've implemented the functionality of std::rel_ops namespace as a template base class (it defines all comparison operators using only operators < and ==). For me it's a bit weird that it works (so far) properly, also I'm concerned about the 'hacks' used. Can anyone assess the following code and say if I'm just lucky it to work or...

Value initialization and Non POD types

An hour ago I posted an answer here which according to me was correct. However my answer was downvoted by Martin B. He said You're just lucky and are getting zeros because the memory that i was placed in happened to be zero-initialized. This is not guaranteed by the standard. However after reading Michael Burr's answer here and try...

Help compiling and using boost c++ libraries

I am working on a C++ project where I'd like to use boost's serialization libraries. I downloaded and installed the latest boost libraries from boost's home page. When I tried to compile and run the one of boost's demo serialization examples, I got all sorts of errors that looked like this: /usr/local/include/boost/archive/detail/...

multiple top-level windows

A single threaded Win32 GUI application has multiple top-level windows. In a message handler for one of the windows, it displays a modal dialog (for example, by using the MessageBox function). The other windows in the application still work as usual, even though the only thread in the application is waiting for the modal dialog result. ...

Boost Serialize - Serialize data in a custom way

If I'm using Boost Serialization to serialize an Integer: #include <boost/archive/text_oarchive.hpp> #include <iostream> int main() { boost::archive::text_oarchive oa(std::cout); int i = 1; oa << i; } The result will be the following: 22 serialization::archive 5 1 Now I'm curious if and how I could change the way, certa...

What should we consider to use either static linking and dynamic linking?

Possible Duplicates: Static linking vs dynamic linking C++ application - should I use static or dynamic linking for the libraries? What point we should take care before selecting static and dynamic linking? ...

Convert base 16 string to base 256 string in C++, vice versa

Anyone knows how, or any libraries that can be used? Thanks in advance! char * base16Str="1234567F"; char * base256Str; ...

how to resolve ftp site using boost.asio?

Hello: Boost.asio documentation doesn't support any ftp examples. `boost::asio::io_service io_service; tcp::resolver resolver(io_service); tcp::resolver::query query("www.boost.org", "http"); tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);` that resolve http site and get an HTTP endpoint. but tcp::resolver::que...

Shared object symbol resolution

Hi, Suppose I have 2 static Libs S1 and S2 which are different versions of the same lib and have the same C (not C++) interface though implementations are different. 2 shared libs D1 and D2 each of which links to S1 or S2 only. Suppose an application A links with S2 which is the more recent of the static libs and dynamically loads bo...

C++ - binding function

Hello! I have some (library API, so I can't change the function prototype) function which is written the following way: void FreeContext(Context c); Now, at some moment of my execution I have Context* local_context; variable and this is also not a subject to change. I wish to use boost::bind with FreeContext function, but I need to ...

Force QWebView to download web page content in a separate thread?

How can i force QWebView into downloading the webpage and related content in a separate thread? ...

const conflicting

Hello, I have the following class class node { public: node() { } node(const node&); node(luint inID) { ID = inID; } ~node() { neighbors.clear(); } node& operator=(const node&); void addNeighbor(luint); void addNeighbor(const std::vector<luint>& ); void setID(luint inID) { ID = inID; } luint getID() ...