c++

The method used in 3rd-party garbage collector

I am writing to clarify some comments on this website. 1) I know that C++ has no garbage collector. One said that C++ was invented before the idea of garbage collector, so that's the reason. Is that true? I think it makes sense. 2) Whenever garbage collector was discussed, smart point(such as boost::share_ptr) was brought out to be a ...

What are good online introductions to testing and Test Driven Development?

I'm looking for an online introduction to unit testing and TDD. I have virtually no experience with TDD, unit testing, or any other agile methodology. My development environment is C++ on Linux. If there's a quality introduction to unit testing and TDD that uses C++ as the example language, that'd be great. If not then a general intr...

C++ functions taking values, where they should be taking references

I'm just learning c++, and coming from c, some function calls I'm seeing in the book confuse me: char a; cin.get(a); In C, this couldn't possibly work, if you did that, there would be no way to get the output, because you are passing by value, and not by reference, why does this work in c++? Is referencing and dereferncing made implic...

Using C++ types in an ANTLR-generated C parser

I'm trying to use an ANTLR v3.2-generated parser in a C++ project using C as the output language. The generated parser can, in theory, be compiled as C++, but I'm having trouble dealing with C++ types inside parser actions. Here's a C++ header file defining a few types I'd like to use in the parser: /* expr.h */ enum Kind { PLUS, MI...

Remove dependancy constants from enum definition

I am trying to safely remove a dependency from my project by using opaque structures and forward declarations but like most I am still stuck on my enums. The header file dependency I am trying to remove from my header files has defined constants that I want to set my enumeration's values to. Something like this // depends header #defi...

Eliminate repetition in C++ code?

Given the following: StreamLogger& operator<<(const char* s) { elements.push_back(String(s)); return *this; } StreamLogger& operator<<(int val) { elements.push_back(String(asString<int>(val))); return *this; } StreamLogger& operator<<(unsigned val) { elements.push_back(String(asString<unsigned>(val))); return *this; } Str...

can declared functions be called without a body

Can you call a function that has no body but is declared in the header in your code?? Please read below for my situation. I am learning c++ so if my terminology is off then you know why. Any how, I am reading this book called "Advanced 2D Game Development" so if anyone's read the book then maybe they can help me out. In c++ he set 4 ext...

Why can't I initialize my static data member in my constructor

Hi, I read the answer in parashift but i need bit details as to why compiler wont allow to define static member variable in constructor. Answer will be highly appreciated. Thanks. ...

istringstream - how to do this?

I have a file: a 0 0 b 1 1 c 3 4 d 5 6 Using istringstream, I need to get a, then b, then c, etc. But I don't know how to do it because there are no good examples online or in my book. Code so far: ifstream file; file.open("file.txt"); string line; getline(file,line); istringstream iss(line); iss >> id; getline(file,line); iss >> ...

Does "Return value optimization" cause undefined behavior?

Reading this Wikipedia article pointed by one of the repliers to the following question: http://stackoverflow.com/questions/2323225/c-copy-constructor-temporaries-and-copy-semantics I came across this line Depending on the compiler, and the compiler's settings, the resulting program may display any of the following outputs: Doesn...

C++ overload >> for ifstream on mac pointer being freed was not allocated

Hello friends, I am trying the following code and it fails with the following error: malloc: *** error for object 0x10000d8c0: pointer being freed was not allocated *** set a breakpoint in malloc_error_break to debug Program received signal: “SIGABRT”. Here are contents of file input.txt : It has full permissions and file is success...

linked list and Red/Black tree in c# - reference problem ?

Hey, I'm pretty new to c#, and i'm trying to understand something pretty basic. I want to implement a RBTree and a linked list , so i create : public class RBTreeNode { // PROPERTIES public RBTreeNode left; public RBTreeNode right; public RBTreeNode parent; public String Color; public In...

Any exit status without explicitly using return /exit

This actually bugging me from quite sometime now.The question is like this : How to set the the exit status of a program to any value without explicitly using return/exit in gcc/g++ ? Let us consider this piece of code : (Takes input from stdin and print it to the stdout until a zero input 0 is encountered) #include <stdio.h> int main(...

"No source available for main()" error when debugging simple C++ in Eclipse with gdb

Hi, I'm having trouble debugging a C++ program in Eclipse (the latest RC of Helios, updated with latest CDT from within itself) on OSX. The program is very simple (esentially Lesson 2 from NeHe's OpenGL tutorials), consisting of one cpp file and, using OpenGL and Cocoa frameworks, and linking with libSDL.a and libSDLmain.a. The struct...

How to determine the version of the C++ standard used by the compiler?

How do you determine what version of the C++ standard is implemented by your compiler? As far as I know, below are the standards I've known: C++03 C++98 ...

Use rspec to test C/C++ program

Hi, Is Rspec ruby/rails specific? Is it possible to use it as a test framework for C/C++ program? ...

Using Microsoft ACM without a sound card

Is it possible to make use of the Microsoft acmStreamConvert() method and associated ACM functionality without the machine in question having a sound device? I wish to do conversion/compression of various audio types in my application on a machine that may not have a sound card. Thanks. ...

Advantage of SQL_TXN_SERIALIZABLE over SQL_TXN_REPEATABLE_READ in DB2 and C++

Hi, We are facing a problem in our application. We have two instances of our monitoring application. The application behaviour is as follows: Step 1. Monitor the ftp folder in a loop Step 2. If files are present, insert the file details to DB for the all files Step 3. Read the file details from the DB and process it Step 4. Once the fi...

boost::asio: thread local asynchronous events.

I will be creating x amount of threads in my server-app. x will be the amount of cores on the machine, and these threads will be (non-hyperthread) core-bound. Naturally with this scheme I would like to distribute incoming connections across the threads with the aim of ensuring that once a connection is assigned to a thread, it will only ...

casting operator - const vs non-const

I have this here code sample: class Number { int i; public: Number(int i1): i(i1) {} operator int() const {return i;} }; What are the implications of removing the const modifier from the casting operator? Does it affect auto casting, and why? ...