g++

Invalid function declaration. DevC++

Why do I get invalid function declaration when I compile the code in DevC++ in Windows, but when I compile it in CodeBlocks on Linux it works fine. #include <iostream> #include <vector> using namespace std; //structure to hold item information struct item{ string name; double price; }; //define sandwich, chips, and drink str...

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...

segfault during __cxa_allocate_exception in SWIG wrapped library

While developing a SWIG wrapped C++ library for Ruby, we came across an unexplained crash during exception handling inside the C++ code. I'm not sure of the specific circumstances to recreate the issue, but it happened first during a call to std::uncaught_exception, then after a some code changes, moved to __cxa_allocate_exception durin...

g++ problem with -l option and PostgreSQL

Hi I've written simple program. Here a code: #include <iostream> #include <stdio.h> #include <D:\Program Files\PostgreSQL\8.4\include\libpq-fe.h> #include <string> using namespace std; int main() { PGconn *conn; PGresult *res; int rec_count; int row; int col; cout << ...

Basic compile issue with QT4

I've been trying to get a dead simple listing from a university textbook to compile with the newest QT SDK for Windows I downloaded last night. After struggling through the regular nonsense (no make.bat, need to manually add environment variables and so on) I am finally at the point where I can build. But only one of the two libraries se...

Compiling a Windows C++ program in g++

I'm trying to compile a Windows C++ program in g++. This is what I get. /usr/include/c++/4.4/backward/backward_warning.h:28:2: warning: #warning This file includes at least one deprecated or antiquated header which may be removed without further notice at a future date. Please use a non-deprecated interface with equivalent functionalit...

How to use gdb to find a floating point exception in g++ code

I have a g++ program that runs without user input. Somewhere the program is interrupted and it says "Floating point exception." Can gdb help me find what's causing this in my code? How? ...

Seeking to a line in a file in g++

Is there a way that I can seek to a certain line in a file to read or write data? Let's say I want to write some data starting on the 10th line in a text file. There might be some data already in the first few lines, or the file could even be empty. Is there a way I can seek directly to the line I want without having to worry about wh...

How to convert binary read/write to non-binary read/write in C++

I have some C++ code from somewhere that reads and writes data in binary format. I want to see what it's reading and writing in the file, so I want to convert it's binary read and write to non-binary read and write. Also, when I convert the binary write to non-binary write, I want it to still be able to read in the information correctly...

Undefined template methods trick ?

A colleague of mine told me about a little piece of design he has used with his team that sent my mind boiling. It's a kind of traits class that they can specialize in an extremely decoupled way. I've had a hard time understanding how it could possibly work, and I am still unsure of the idea I have, so I thought I would ask for help her...

pure/const functions in C++

Hi, I'm thinking of using pure/const functions more heavily in my C++ code. (pure/const attribute in GCC) However, I am curious how strict I should be about it and what could possibly break. The most obvious case are debug outputs (in whatever form, could be on cout, in some file or in some custom debug class). I probably will have a ...

What C++ library do I need to get this program to compile

When I try to compile my program I get these errors: btio.c:19: error: ‘O_RDWR’ was not declared in this scope btio.c:19: error: ‘open’ was not declared in this scope btio.c: In function ‘short int create_tree()’: btio.c:56: error: ‘creat’ was not declared in this scope btio.c: In function ‘short int create_tree(int, int)’: btio.c:71: e...

How to traverse a Btree?

I have a Btree and I'm trying to figure out how traverse it so that the keys are displayed ascending order. All I can figure out is that this can be done with a recursive function. What's the pseudo-code to do it? ...

Using C++ to find out how many lines are in a text file

My C++ program needs to know how many lines are in a certain text file. I could do it with getline() and a while-loop, but is there a better way? ...

make include directive and dependency generation with -MM

I want a build rule to be triggered by an include directive if the target of the include is out of date or doesn't exist. Currently the makefile looks like this: program_NAME := wget++ program_H_SRCS := $(wildcard *.h) program_CXX_SRCS := $(wildcard *.cpp) program_CXX_OBJS := ${program_CXX_SRCS:.cpp=.o} program_OBJS := $(program_CXX_OB...

How to find the byte offset of an object in C++?

Let's say I create 5 objects, all from the same class. Would the byte offset of the first object be 0? How would I find out the byte offset of the other objects? ...

Getting out of a recursive function at the topmost level in C++

Say that you are several levels deep into a recursive function. The function was originally called in main. Is there a way for you to break out of the recursion and go straight back to main without having to go through all the other functions above? ...

How do I add dependencies to this header file

Here is a simple header file for six different programs. This Makefile used to work just fine, but then I changed the programs to include other implementation files. This Makefile needs to get changed so that if the implementation files change the files that include those implementation files get recompiled. all: load list show add del...

How to tell the MinGW linker not to export all symbols?

Hello, I'm building a Windows dynamic library using the MinGW toolchain. To build this library I'm statically linking to other 2 which offer an API and I have a .def file where I wrote the only symbol I want to be exported in my library. The problem is that GCC is exporting all of the symbols including the ones from the libraries I'm l...

Formatting an integer in C++

I have an 8 digit integer which I would like to print formatted like this: XXX-XX-XXX I would like to use a function that takes an int and returns a string. What's a good way to do this? ...