c++

Do rvalue references allow implicit conversions?

Is the following code legal? std::string&& x = "hello world"; g++ 4.5.0 compiles this code without any problems. ...

Inlined constructors? Explain this behavior[C++]

Consider this code #include <iostream> #include <cstdio> using namespace std; class Dummy { public: Dummy(); }; inline Dummy::Dummy() { printf("Wow! :Dummy rocks\n"); } int main() { Dummy d; } All is good here! Now I do this modification. I move the declaration of Dummy to "dummy.h". class Dummy { public: Dummy()...

C++ : iterating the vector

I'm very new to C++ and I'm trying to learn the vector in C++.. I wrote the small program as below. I like to foreach(var sal in salaries) like C# but it doesn't allow me to do that so I googled it and found that I have to use iterator.. Im able to compile and run this program but I dont get the expected output.. I'm getting "0 0 0 0 0 ...

Confusion in C++

I'm very new to C++ and I'm currently learning it. I got a few questions.. What is the differences between void DoSomething(const Foo& foo) and void DoSomething(Foo foo)? If we don't specify & then the instance of Foo will be passed by value ( not reference ). It will be the same as having const + & in argument except no checking at co...

Tool to identify the similarities in logic between a function of C and C++

Is there a tool in either Linux/Windows that would enable us to determine if a logic of the particular function in C is same as that of a particular function in C++ ? ...

[Qt/N900] Can someone tell me how to use this type of a listbox ?

Hey guys, I have a question .. I think I sort of already know the answer to this but I thought I should just get it confirmed first .. I want to have a Maemo 5 Value Button (like in the first picture below), which when I press opens up a second dialog box which has 2 lists which show a bunch of numbers (similar to the second picture belo...

Multiple declaration for function

I have a function declared in my base class and specified as virtual, I am trying to re-declare it in a derived class but I'm getting a multiple declaration error. Anyone know if I'm missing something here? class Field { public: virtual void display() = 0; virtual int edit() = 0; virtual bool editable() cons...

Where in memory are variables stored in C++?

If I have code like this: int e; int* f; int main() { int a, b, c; int* d; } Where in memory are these variables stored? And, what's the problem with defining global variables (out of a function, like main in this case)? ...

i am out of ideas...

i have an assignment,and i need help!! in a given 2D ARRAY of integers and a given MAXIMUM number of steps the program supposed to find a path, from one corner to the one in front of it, which sums the biggest numbers in limited number of steps. this supposed to be done with BACKTRACKING RECURTION... ...

Multithreading in C++ ... where to start?

I'd like to start learning multithreading in C++. I'm learning it in Java as well. In Java, if I write a program which uses multithreading, it will work anywhere. However in C++, doesn't multithreading rely on platform-specific API's? If so, that would seem to get in the way of portability. How can I do multithreading in C++ without cau...

need some help in making slider control

i have made the slider control in c++ using MFC. there is my code. void CImageAnalyserDlg::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { if(nSBCode == SB_THUMBPOSITION) { slidervalue.Format(_T("%d"), nPos); UpdateData(false); } else { CDialog::OnHScroll(nSBCode, nPos, pScrollBar); } } every thing is don...

Clear an Array to NULL without knowing the type

Hi, I have to create a function that can take in an array of pointers with a known size, and set all the pointers to NULL. The caveat is that I don't know the type beforehand. This is what I have tried so far: template <typename T> static void Nullify(T** _Array, int _Size, unsigned int _SizeOf) { for (int i = 0; i < _Size; ...

Two dimensional arrays allocation problem

Hello all, this is an interview question my friend was asked yesterday. The question was something like: will this program crash with an "access violation" error or not? I looked at it for a while and thought no, it won't. But actually trying this out in visual studio proved me wrong. I cannot figure out what happens here... or to be mo...

<string.h> conflicting with my own String.h

Hi! I have a project that was compiling ok within g++(I can't see the version right now) and now on xCode it is not. I think that I got the problem now... I have a String.h file in my project and it seems tha the xCode compiler(that is gcc) is trying to add my own string file from the < cstring >... I am not sure of it, but take a look ...

I created a new project and I want to rename the default forms name from Form1 to LabReportsC

I am trying to rename the default Form1 form name to LabReportsC name. But I keep getting the following errors. Error 1 error C2872: 'LabReportsC' : ambiguous symbol C:Visual Studio 2010C++ ProjectsLabReportsCLabReportsCLabReportsC.cpp 16 Error 2 error C2061: syntax error : identifier 'LabReportsC' C:Visual Studio 2010C++ ProjectsLabRe...

How can I make a third-party library thread-safe for use with Boost threads?

I am using a third-party C++ library (OpenFst), which is not particularly designed to be thread-safe. It does have some unused Mutex classes in there, though. Now I would like to call some functions from that library and run them in Boost threads. How can I do that? Do I just have to write additional Mutex classes? In particular, some ...

C++ header file question

Hi, I was trying out some c++ code while working with classes and this question occurred to me and it's bugging me a little. I have created a header file that contains my class definition and a cpp file that contains the implementation. If I use this class in a different cpp file, why am I including the header file instead of the cp...

[Qt/N900/Maemo5] Strange compilation errors when I use Maemo5 specific Qt classes .. !

Hey guys .. I recently tried to use some Maemo5 specific classes (e.g. QMaemo5ListPickSelector, etc ..), and I'm getting some strange compile time errors .. Here is a small code I was trying out: QMaemo5ValueButton *x = new QMaemo5ValueButton("Hello"); QStandardItemModel model (10,2); int i,j,k; for(j=0;j<=1;j++) { k=0; for(i=0...

What's the best small C++ package to compute the largest eigenvalue of a matrix?

I need to compute the largest eigenvalue of a (sparse) matrix. I implemented the power iteration method, but it is too slow to converge, so I'd like to use a package for it. Does anyone have a recommendation? What is the best C++ eigenvalue computation package? Preferably one that is small and easy to compile. ...

Algorithms that can take an N length string and return a fixed size unique value?

I'm looking to add basic licensing to my application. I want to take in the user's name as a parameter and return a unique, fixed length code (sort of like MD5) What are some algorithms that can do this? Thanks ...