c++

QT qmake lowercases my custom widget names

I'm using QT 4.6 on Linux and Windows, and on Linux, it insists on including my QScrollPane by qscrollpane.h App.pro: HEADERS += widgets/QScrollPane.h The section from mainform.ui <widget class="QScrollPane" name="ListView"> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>500</width> <height>490</height>...

Need to interface to a C++ DLL

Hi, I need to call a C++ API from C#. I have been able to call the API, but the char[] parameters do not seem to be marshalling correctly. Here's the C++ signature: Create2ptModel(double modelPowers[2], double modelDacs[2], int pclRange[2], double targetPowers[32], double *d...

Setting precision on std::cout in entire file scope - C++ iomanip

Hi all, I'm doing some calculations, and the results are being save in a file. I have to output very precise results, near the precision of the double variable, and I'm using the iomanip setprecision(int) for that. The problem is that I have to put the setprecision everywhere in the output, like that: func1() { cout<<setprecision(12)<<...

Name lookup for names not dependent on template parameter in VC++2008 Express. Is it a bug?

While experimenting a bit with C++ templates I managed to produce this simple code, for which the output is different, than I expected according to my understanding of C++ rules. void bar(double d) { std::cout << "bar(double) function called" << std::endl; } template <typename T> void foo(T t) { bar(3); } void bar(int i) { ...

Safe to cast pointer to a forward-declared class to its true base class in C++?

In one header file I have: #include "BaseClass.h" // a forward declaration of DerivedClass, which extends class BaseClass. class DerivedClass ; class Foo { DerivedClass *derived ; void someMethod() { // this is the cast I'm worried about. ((BaseClass*)derived)->baseClassMethod() ; } }; Now, DerivedClass is (in ...

functionality of cin in c++

I'm a bit confused by the results of the following function: int main() { string command; while(1) { cin >> command; if(command == "end") return 0; else cout << "Could you repeat the command?" << endl; } return 0; } First of all - the output line ("could you...") repeats once for each individual ...

How to bundle C/C++ code with C-shell-script?

I have a C shell script that calls two C programs - one after the another with some file handling before, in-between and afterwards. Now, as such I have three different files - one C shell script and 2 .c files. I need to give this script to other users. The problem is that I have to distribute three files - which the users m...

Can a single argument constructor with a default value be subject to implicit type conversion

I understand the use of the explicit keyword to avoid the implicit type conversions that can occur with a single argument constructor, or with a constructor that has multiple arguments of which only the first does not have a default value. However, I was wondering, does a single argument constructor with a default value behave the same...

Invisible ActiveX that takes a string

I need to adapt a simple function (let's say) int printText(string) written using an MFC library (this function prints the text on a particular printer whose driver lib is completely developed by MFC), to two applications developed the first in LabView and the second in Java (Eclipse RCP). I've thought that an ActiveX component is the ...

Refactoring thick client legacy application

I am working on a fat client legacy C++ application which has a lot of business logic mixed in with the presentation side of things. I want to clean things out and refactor the code out completely, so there is a clear seperation of concerns. I am looking at MVC or some other suitable design pattern in order to achieve this. I would like...

Calling a function that uses object members without giving the object.

void CVisualStudioDemoDoc::updateLine(void) { int newln = GetLineNumber(p_buf); reinterpret_cast<CVisualStudioDemoView *>(m_viewList.GetHead())->SetCurrentLineNumber(ln, newln); ln = newln; } I want to call this function from another part of my code without having to give the object pointer and include headers. I want to call it just ...

Biased Random Number Generator

I am looking for a random number generator that can be biased. For instance, say I want a random number between 1-5, with the probability being: 1: Comes up 20% of the time 2: Comes up 10% of the time 3: Comes up 40% of the time 4: Comes up 25% of the time 5: Comes up 5% of the time Is there anything in the standard library, or other...

im counting the number of characters in a file but i want to count the number of words that are less than 5 and 6 or greater.

i want to do this: reads the words in the file one at a time. (Use a string to do this) Counts three things: how many single-character words are in the file, how many short (2 to 5 characters) words are in the file, and how many long (6 or more characters) words are in the file. HELP HERE im not sure on how about reading file into a st...

C++ Windows HTTP

Hi, I'm looking for a basic tutorial for connecting to a domain and downloading the index file . Anyone that can link me a good example or anything. ...

Map a 32 bit float to a 32 bit integer

Is there a way to map floats to ints or unsigned ints so that with the exception of NaN, order is preserved? So if a and b are floats, and F is the mapping function, a < b implies F(a) < F(b) and a == b implies F(a) == F(b) ...

Missing A Detail About Boost (.lib files)

Where do I find the lib files for linking my program when using some Boost libraries? Decided to try its threading functionality but I am getting Error 6 fatal error LNK1104: cannot open file 'libboost_thread-vc90-mt-gd-1_42.lib' InterviewPractice after I include Error 6 fatal error LNK1104: cannot open file 'libboo...

Foo f = Foo(); // no matching function for call to 'Foo::Foo(Foo)' ... huh?!

class Foo { public: explicit Foo() {} explicit Foo(Foo&) {} }; Foo d = Foo(); error: no matching function for call to 'Foo::Foo(Foo)' I tried changing Foo(Foo&) to Foo(Foo) as the error suggests, which AFAIK is not a valid constructor, and sure enough I get: error: invalid constructor; you probably meant ‘Foo (const F...

What Does an OS Actually Do?

What exactly does an operating system do? I know that operating systems can be programmed, in, for example, C++, but I previously believed that C++ programs must be run under an operating system? Can somebody please explain and give links? thanks in advance, ell ...

Operator+ for a subtype of a template class.

I have a template class that defines a subtype. I'm trying to define the binary operator+ as a template function, but the compiler cannot resolve the template version of the operator+. #include <iostream> template<typename other_type> struct c { c(other_type v) : cs(v) {} struct subtype { subtype(other_type v) : val(v) {} other_ty...

How to demonstrate memory error using arrays in C++

I'm trying to think of a method demonstrating a kind of memory error using Arrays and C++, that is hard to detect. The purpose is to motivate the usage of STL vector<> in combination with iterators. Edit: The accepted answer is the answer i used to explain the advantages / disadvantages. I also used: this ...