c++

overloaded stream insertion operator with a vector

I'm trying to write an overloaded stream insertion operator for a class who's only member is a vector. It's a vector of Points, which is a struct containing two doubles. I figure what I want is to insert user input (a bunch of doubles) into a stream that I then send to a modifier method. I'm working off other stream insertion examples su...

keybd_event is not working right =(

I can't get this to work right. This should press left for 1 second then wait 10 seconds, then right 1 second, etc.: keybd_event(0x25, 0xCB, 0, 0); // press left cout << "Ldown\n"; // so i know it worked Sleep(1000); // hold it for 1sec keybd_event(0x25, 0xCB, KEYEVENTF_KEYUP, 0);// let go of the key co...

Reference Parameters in C++: VERY basic example please.

I am trying to understand how to use reference parameters. There are several examples in my text, however they are too complicated for me to understand why and how to use them. Could anyone give me the MOST basic example of how/why to use one, and perhaps the difference with or without it (what would happen if you didn't attach the '&')....

How does the below program work in c++?

I have just created 2 pointers which has undefined behavior and try to invoke a class member function which has no object created ? I don't understand this? #include<iostream> using namespace std; class Animal { public: void talk() { cout<<"I am an animal"<<endl; } }; class Dog : public Animal { public: void talk() ...

Classes, constructor and pointer class members

I'm a bit confused about the object references. Please check the examples below: class ListHandler { public: ListHandler(vector<int> &list); private: vector<int> list; } ListHandler::ListHandler(vector<int> &list) { this->list = list; } Because of the internal vector<int> list; definition, here I would be wasting memory r...

Higher-kinded Types with C++

This question is for the people who know both Haskell (or any other functional language that supports Higher-kinded Types) and C++... Is it possible to model higher kinded types using C++ templates? If yes, then how? EDIT : From this presentation by Tony Morris: Higher-order Polymorphism : Languages such as Java and C# have first-o...

What is a NULL value

I am wondering , what exactly is stored in the memory when we say a particular variable pointer to be NULL. suppose I have a structure, say typdef struct MEM_LIST MEM_INSTANCE; struct MEM_LIST { char *start_addr; int size; MEM_INSTANCE *next; }; MEM_INSTANCE *front; front = (MEM_INSTANCE*)malloc(sizeof(MEM_INSTANCE*))...

Using ASSERT and EXPECT in GoogleTest

While ASSERT_* macros cause termination of test case, EXPECT_* macros continue its evaluation. I would like to know which is the criteria to decide whether to use one or the other. ...

Varying performance of MSVC release exe

Hello everyone, I am curious what could be the reason for highly varying performance of the same executable. Sometimes, I run it and it takes 20 seconds and sometimes it is 110. Source is compiled with MSVC in Release mode with standard options. The code is here: vector<double> Un; vector<double> Ucur; double *pUn, *pUcur; ... // time...

Actual long double precision does not agree with std::numeric_limits

Working on Mac OS X 10.6.2, Intel, with i686-apple-darwin10-g++-4.2.1, and compiling with the -arch x86_64 flag, I just noticed that while... std::numeric_limits<long double>::max_exponent10 = 4932 ...as is expected, when a long double is actually set to a value with exponent greater than 308, it becomes inf--ie in reality it only has...

valgrind complains doing a very simple strtok in c

Hi I'm trying to tokenize a string by loading an entire file into a char[] using fread. For some strange reason it is not always working, and valgrind complains in this very small sample program. Given an input like test.txt first second And the following program #include <stdio.h> #include <string.h> #include <stdlib.h> #include <s...

Prevent committing code with svn if certain obsolete C/C++ functions are used

Is there a way to prevent developers from committing code when certain unsafe or obsolete functions are used? For example: scanf atoi gets etc.. ...

"Find all References" for operator overload in visual studio or other IDE

Hi Im looking at some codes (in C++) and it gets quite confusing when there is operator overloading. Is there a simpler way to find out whether "()" or any other symbol is overloaded? ...

wopen calls when porting to Linux

I have an application which was developed under Windows, but for gcc. The code is mostly OS-independent, with very few classes which are Windows specific because a Linux port was always regarded as necessary. The API, especially that which gets called as a direct result of user interaction, is using wide char arrays instead of char arr...

Floating point precision in Visual C++

HI, I am trying to use the robust predicates for computational geometry from Jonathan Richard Shewchuk. I am not a programmer, so I am not even sure of what I am saying, I may be doing some basic mistake. The point is the predicates should allow for precise aritmthetic with adaptive floating point precision. On my computer: Asus p...

how to compile with llvm and g++?

Hi, I use a fedora-11 system and recently I installed llvm ( sudo yum -y install llvm llvm-docs llvm-devel ). When I search for llvm I get them in /usr/bin. some of the links to the binaries are broken(llvm-gcc,llvm-g++,llvm-cpp,etc.) the include files are found within /usr/include/llvm and libs at /usr/lib/llvm. How to compile them usi...

Cant free memory.

In code: template<class T,int row, int col> void invert(T (&a)[row][col]) { T* columns = new T[col * row]; T* const free_me = columns; T** addresses = new T*[col * row]; T** const free_me_1 = addresses; /*cpy addresses*/ for (int i = 0; i < row; ++i) { for (int j = 0; j < col; ++j) { *addresses = &a[i][j]; ++ad...

Where to find __sync_add_and_fetch_8?

I got errors when trying to use __sync_add_and_fetch: test8.cpp:(.text+0x90e): undefined reference to `__sync_add_and_fetch_8' collect2: ld returned 1 exit status Please kindly advise how to rectify this. Specs: GCC/G++: 4.4.1 GNU/Linux 2.6.32 SMP i686 Many thanks! EDIT: In addition to the answer provided, one can use -march=i586 ...

Does GetSystemInfo (on Windows) always return the number of logical processors?

Reading up on this, and specifically reading the Microsoft docs, it looks like it should be returning the number of PHYSICAL processors, and that you should use GetLogicalProcessorInformation to figure out how many LOGICAL processors you have. Here's the doc I found on the SYSTEM_INFO structure: http://msdn.microsoft.com/en-us/library/m...

Passing array by ref.

Ref. to my last post and sellibitze's comment to that post on passing array by ref rather than by value, why is it that when I'm passing array by value compiler can deduce arguments but it won't do it if I pass it by value? template<class T,int row, int col> void invert(T (&a)[row][col]) //NOTE AMPERSAND in main with declaration above...