c++

What is the difference between declaring an enum with and without 'typedef'?

The standard way of declaring an enum in C++ seems to be: enum <identifier> { <list_of_elements> }; However, I have already seen some declarations like: typedef enum { <list_of_elements> } <identifier>; What is the difference between them, if it exists? Which one is correct? ...

Can a trait state if a C++ class has a default constructor?

Traits classes can be defined to check if a C++ class has a member variable, function or a type (see here). Curiously, the ConceptTraits do not include traits to check if a C++ class defines a default constructor or given constructor? Can traits be used to check the constructor presence? If yes, how? If not, why it is not possible? ...

How do I get Eclipse CDT to ignore files

I have a C++ project in Eclipse. The project uses Perforce and Eclipse has the Perforce plugin installed. Everything was fine, until I decided to create a git repo in my project. I created the git repo to snapshot some changes which I wasn't ready to commit. Everything was fine until I refreshed my files in Eclipse. Two problems hav...

What is the rationale to not allow overloading of C++ conversions operator with non-member functions

C++0x has added explicit conversion operators, but they must always be defined as members of the Source class. The same applies to the assignment operator, it must be defined on the Target class. When the Source and Target classes of the needed conversion are independent of each other, neither the Source can define a conversion operator...

QWidget keyPressEvent override

Hi there, I'm trying for half an eternity now overriding QWidgets keyPressEvent function in QT but it just won't work. I've to say i am new to CPP, but I know ObjC and standard C. My problem looks like this: class QSGameBoard : public QWidget { Q_OBJECT public: QSGameBoard(QWidget *p, int w, int h, QGraphicsScene *s); signals: v...

can not find my lib files to link

I am trying to find a lib file that I created. I changed the configuration type to static lib. Then I rebuild the application. When I go to the debug folder in windows, I see the .lib file. but when I create a new application and try to add it to "additional Library Directories" I go to the exact folder and it does not show up. ...

How do I declare and initialize a 2d int vector in C++?

I'm trying to do something like: #include <iostream> #include <vector> #include <ctime> class Clickomania { public: Clickomania(); std::vector<std::vector<int> > board; bool move(int, int); bool isSolved(); void print(); void pushDown(); }; Clickomania::Clickomania() : board(12, ...

fatal error C1016: #if[n]def expected an identifier

// File: Lab13Frac.h #include <iostream> using namespace std; #ifndef "Lab13Frac.h" #define "Lab13Frac.h" // prototpes #endif ...

Do I need to check capacity before adding an element to a vector in c++ ?

Hi dear all, I am a newbie to c++ STL vectors so sorry for silly questions in advence. :) In my program, I have a vector which needs to store unknown number of elements. Do I have to check if the vector has achieved its max_size before adding an new element to it ? Will a c++ compiler throw an exception automatically when a program trie...

Why is my simple recusive method's final return value always off by 1?

I'm attempting to create a text-based version of this game: http://www.cse.nd.edu/java/SameGame.html Here is the code I have so far: #include <iostream> #include <vector> #include <ctime> class Clickomania { public: Clickomania(); std::vector<std::vector<int> > board; int move(int, int); bool isSolv...

Having template function defination in cpp file - Not work for VC6

I have the following source code : // main.cpp #include "a.h" int main() { A::push(100); } // a.cpp #include "a.h" template <class T> void A::push(T t) { } template void A::push(int t); // a.h #ifndef A_H class A { public: template <class T> static void push(T t); }; #endif The code compiled charming and n...

Dialog created after first becomes unresponsive unless created first?

After creating the initial dialog box that works perfectly fine, I create another dialog box when the Join Game button is pressed. The dialog box is created and show successfully, however I am unable to type in the edit box or even press or exit the dialog. Does anyone understand how to fix this or why it happens? I made sure the dialog ...

C++ Char without Limit

I'm pretty well versed in C#, but I decided it would be a good idea to learn C++ as well. The only thing I can't figure out is chars. I know you can use the string lib but I also want to figure out chars. I know you can set a char with a limit like this: #include <iostream> using namespace std; int main() { char c[128] = "limited ...

error C2059: syntax error : ']', i cant figure out why this coming up in c++

void display_totals(); int exam1[100][3];// array that can hold 100 numbers for 1st column int exam2[100][3];// array that can hold 100 numbers for 2nd column int exam3[100][3];// array that can hold 100 numbers for 3rd column int main() { int go,go2,go3; go=read_file_in_array; go2= calculate_total(exam1[],exam2[],exam3[]); ...

Char * reallocation in C++

Hi, I need to store a certain amount of data in the "char *" in C++, because I want to avoid std::string to run out of memory, when exceeding max_size(). But the data comes in data blocks from the network so I need to use reallocation every time I get the data block. Is there any elegant solution for char * reallocation and concatenatio...

c++ thread running time

I want to know whether I can calculate the running time for each thread. I implement a multithread program in C++ using pthread. As we know, each thread will compete the CPU. Can I use clock() function to calculate the actual number of CPU clocks each thread consumes? my program looks like: Class Thread () { Start(); Run(); Computing(...

ISO/IEC Website and Charging for C and C++ Standards

The ISO C Standard (ISO/IEC 9899) and the ISO C++ Standard (ISO/IEC 14882) are not published online; instead, one must purchase the PDF for each of those standards. I am wondering what the rationale is behind this... is it not detrimental to both the C and C++ programming languages that the authoritative specification for these languages...

Question regarding inheritance in wxWidgets.

Currently I'm attempting to write my own wxObject, and I would like for the class to be based off of the wxTextCtrl class. Currently this is what I have: class CommandTextCtrl : public wxTextCtrl { public: void OnKey(wxKeyEvent& event); private: DECLARE_EVENT_TABLE() }; Then later on I have this line of code, ...

What are the disadvantages of using templates?

Some of the disadvantages would be its syntax is complex compiler generates extra code ...

How to add a property to a module in boost::python?

You can add a property to a class using a getter and a setter (in a simplistic case): class<X>("X") .add_property("foo", &X::get_foo, &X::set_foo); So then you can use it from python like this: >>> x = mymodule.X() >>> x.foo = 'aaa' >>> x.foo 'aaa' But how to add a property to a module itself (not a class)? There is scope().a...