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?
...
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?
...
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...
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...
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...
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.
...
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, ...
// File: Lab13Frac.h
#include <iostream>
using namespace std;
#ifndef "Lab13Frac.h"
#define "Lab13Frac.h"
// prototpes
#endif
...
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...
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...
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...
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 ...
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 ...
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[]);
...
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...
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(...
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...
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, ...
Some of the disadvantages would be
its syntax is complex
compiler generates extra code
...
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...