c++

If I implement an operator for a class, is it possible that it won't be inline?

Are operators always inlined? struct foo { void operator ()() { // Do tons of work. } }; int main() { foo f; f(); } ...

multiheritance in C++, different files : "Expected class-name before ',' token"

I am getting this error "Expected class-name before ',' token" and "Expected class-name before '{' token" in MainController.h I think I am including files as needed, also doing #ifndef HEADER_H #define HEADER_H, etc in all headers, I had no errors until I wrote MainController class. I have no idea why this error appears. What am I missi...

Tiny crashing program

The following program compiles with g++ but then crashes upon running: class someClass { public: int const mem; someClass(int arg):mem(arg){} }; int main() { int arg = 0; someClass ob(arg); float* sample; *sample = (float)1; return 0; } The following program does not crash: int main() { float* samp...

C++ and Objective-C Combination

Hi, I need to know whether I can write the whole class in C++ and use it in XCode using Objective-C? I need to write a code to query HTML using POST method and I think the best approach is to use either C++ or C#. Umair ...

Doubt: Explicit constructor call in C++

Hi, 1) what is the return value of following statement: obj.classX::classX(); 2) Another doubt regarding constructors in C++: classX(); creates an object. What is the expanded code generated by compiler? Thanks TNA. ...

Why are C++ classes allowed to have zero data members?

question about c++ why minimal number of data members in class definition is zero i think it should be one , i.e pointer to virtual table defined by compiler thanks a lot ...

int (*p) [4] ??

Hi .. int (*p) [4] ; Is "p" pointer to array of 4 integers ?? or what ?? and How can I call "new" for this pointer ?? ...

Weird C++ preprocessor problem

Hi, I've distilled my problem down to this code snippet - but it is a part of a larger program so I don't want a different way to do this - I need a way to make this work! When I generate a preprocessed file from this code: #define OUTER(a, b) \ a##b #define INNER(c, d) \ c##d enum foo { OUTER(INNER(x, y), z) }; // line 1...

Opencv expected constructor, desctructor or type conversion

When I compile the code below I get the following errors: ./main.cpp:150: error: expected constructor, destructor, or type conversion before ‘(’ token ../main.cpp:154: error: expected constructor, destructor, or type conversion before ‘(’ token ../main.cpp:156: error: expected constructor, destructor, or type conversion before ‘(’ toke...

C/C++ - is returning void a valid code?

I found out that the following code gets accepted by Visual C++ 2008 and GCC 4.3 compilers: void foo() { } void bar() { return foo(); } I am a bit surprised that it compiles. Is this a language feature or is it a bug in the compilers? What do the C/C++ standards say about this? ...

Projection of polygon onto plane using GSL in C/C++

The general problem is projecting a polygon onto a plane is widely solved, but I was wondering if anybody could make some suggestions for my particular case. I have a planar polygon P in 3-space and I would like to project it onto the plane through the origin that is orthogonal to the unit vector u. The vertices of P and the coordinates...

getting the name of the invoked function

when using either the '.', '->' or '->*' operators is there any way of getting the name of the function invoked (or the name of the variable in the case of '->*' and everything goes. EDIT: Just to clarify I'm not talking about reflection but more something in the line of 'function' basically I want to create an overload of an operator (...

C++ Constructor error. Cannot initialize array of strings

Why cannot initialize my array of strings in my constructor? I get the following error: internal compiler error: Segmentation fault| at these two lines in the constructor: suits = {"Clubs", "Diamonds", "Hearts", "Spades"}; denominations = {"Ace","2","3","4","5","6","7","8","9","10","Jack","Queen","King"}; class Card { publ...

Error compiling Qualnet on Mac: file is not of required architecture

When trying to compile Qualnet on Mac, I got the following error: ld: warning: in ../kernel/obj/mobility_private.o-darwin-x86-gcc-4.0, file is not of required architecture and a bunch of errors for other files in this kind. So I'm wondering if there is anyway to solve the problem. Anxious waiting for help. ...

struct declaration syntax error

I have the following code: #include <iostream> using namespace std; struct stud{ int roll; char name[10]; double marks; } struct stud stud1={1,"ABC",99.9}; struct stud stud2={2,"xyz",80.0}; int main(){ cout<<stud1.marks<<"\n"<<endl; cout<<stud1.name<<"\n"; cout<<stud1.roll<<"\n"; return 0; } But t...

Help with Try Catch

I'm using the GLUTesselator and every once in a while EndContour() fails so I did this: try { PolygonTesselator.End_Contour(); } catch (int e) { renderShape = false; return; } Why would it still crash, it should perform the catch code right? How could...

Limit floating point precision?

Is there a way to round floating points to 2 points? ex: 3576.7675745342556 becomes 3576.76. Thanks ...

Multiple C++ .lib projects to .dll projects, Lua crashes!

Hello, Today I've tried to get Edit & Continue to work in my solution, which looks like this: Game Engine .lib <- Game .lib <- Editor .exe <- Server .exe <- Client .exe Which works nicely. But now I wanted to turn the engine and game .libs into .dlls, so I can use the Edit & Continue ...

Commas in for loop

Why is the following line producing errors? for(int i = 0, int pos = 0, int next_pos = 0; i < 3; i++, pos = next_pos + 1) { // … } error: expected unqualified-id before ‘int’ error: ‘pos’ was not declared in this scope error: ‘next_pos’ was not declared in this scope Compiler is g++. ...

Qt Table and Tree View with the same model

I have a neat Model based off QAbstractItemModel. This has a simple hierarchical tree structure which works perfectly for QTreeView. However, I want the QTableView/QListView to access and display only the leaf nodes( ALL leaf nodes ). What is the best way to do this? I don't want to rebuild the model( because it will be expensive ) and I...