In Python and Ruby, signed integer division truncates towards negative infinity, and signed integer modulus has the same sign the second operand:
>>> (-41) / 3
-14
>>> (-41) % 3
1
However, in C and Java, signed integer division truncates towards 0, and signed integer modulus has the same sign as the first operand:
printf("%d\n", (-41...
Say I have a class definition:
class CustomClass {
int member;
};
Why is the following variable definition compiling and working correctly:
CustomClass CustomClass; // the variable is properly constructed
Should't this confuse the compiler and cause it to indicate an error?
...
I am trying to implement a template class that would be able to tell me if a variable is a class,structure or a basic type.
So far I've come with this:
template< typename T >
class is_class
{
private:
template< typename X >
static char ( &i_class( void(X::*)() ) )[1];
//
template< typename X >
static char ( &i_class...
Hi, I have a class like this:
class MyClass{
public:
MyClass(int Mode);
private:
std::map < int, std::string, CompFunc > data;
};
The data member must use different comparison function according to Mode argument.
if Mode == 1, then use CompFunc1.
if Mode == 2, then use CompFunc2.
etc.
but the CompFunc template argument is f...
I'm subclassing QAbstractItemDelegate. This is my code. Suggestions are welcome:
QWidget *ParmDelegate::createWidget(Parm *p, const QModelIndex &index) const {
QWidget *w;
if (index.column() == 0) {
w = new QLabel(p->getName().c_str());
} else {
if (p->isSection())
return NULL;
w = p->createControl();
...
I was asked in an interview that what is the usage of virtual keyword with a class declaration in C++ and I answered that virtual keyword cannot be used with a class declaration in C++. The interviewer said that it is possible and asked me to test it later.
Now that I have checked it myself I have come to know that this is possible and...
Hi there
When I was in college i did some C/C++, but in near future i was working in PHP, and now I wish to put more time in learning C/C++.
In PHP i was using print_r() or var_dump() in order to display datas from structures or arrays. Do I have such a default functionality in C, in order to see what do i have in a struct or array?
...
I use macros to code unrolled loops like this: (silly example)
#define foreach_small_prime(p, instr) { \
int p; \
p = 2; instr; \
p = 3; instr; \
p = 5; instr; \
p = 7; instr; \
}
foreach_...
I'm having a problem with the call to SQLGetDiagRec. It works fine in ascii mode, but in unicode it causes our app to crash, and i just can't see why. All the documentation i've been able to find seems to indicate that it should handle the ascii/unicode switch internally. The code i'm using is:
void clImportODBCFileTask::get_sqlError...
How do I set up MS Visual Studio 2005 project dependencies such that making a change in a higher level project does not force a recompile of all other projects it depends on.
If I have 5 dll projects, which are related in various ways... Under the 'Project'->'Dependencies' I have identified the next project down, but only down one level...
Hi,
The Windows API function CopyFile has an argument BOOL bFailIfExists that allows you to control whether or not you want to overwrite the target file if it exists.
The boost::filesystem copy_file function has no such argument, and will fail if the target file exists. Is there an elegant way to use the boost copy_file function and o...
Could someone post some sample code showing how to insert text greater than 4000 characters in length into an Oracle 10g CLOB field?
I am using the Oracle OLEDB provider and ATL in C++.
My naive attempt returns the error 'ORA-01704: string literal too long' whenever the text I am attempting to insert goes over 4000 characters in length.
...
Sometimes I need to learn the type of an expression while programming in C or C++. Sometimes there's a good IDE or existent documentation to help me, but sometimes not. I often feel such a construct could be useful:
void (*myFunc)(int);
printf("%s", nameoftype(myFunc)); //"void (*)(int)"
int i, unsigned int u;
printf("%s", nameoftype(i+...
I'm about to develop some sockets related stuff in C++ and would like the software to be as portable between Windows and Linux as possible right from the start (making it portable later is tricky.)
I've looked at different libraries, there is one for C++ from alhem.net and of course there is boost::asio. boost::asio looks very promising...
In the name of efficiency in game programming, some programmers do not trust several C++ features. One of my friends claims to understand how game industry works, and would come up with the following remarks:
Do not use smart pointers. Nobody in games does.
Exceptions should not be (and is usually not) used in game programming for memo...
When I allocate a single object, this code works fine. When I try to add array syntax, it segfaults. Why is this? My goal here is to hide from the outside world the fact that class c is using b objects internally. I have posted the program to codepad for you to play with.
#include <iostream>
using namespace std;
// file 1
class a...
I have following method in my Borland C++ code,
static bool UploadBitstream(void)
{
//Some code Implementation
}
And I'm trying to convert it to DLL and access it in C#.
What are the steps I need to follow to Convert the code DLL
and then use it in C# ??
...
Is it "safe" to give macros names as arguments to other macros to simulate higher order functions?
I.e. where should I look to not shoot myself in the foot?
Here are some snippets:
#define foreach_even(ii, instr) for(int ii = 0; ii < 100; ii += 2) { instr; }
#define foreach_odd(ii, instr) for(int ii = 1; ii < 100; ii += 2) { instr; }...
I have been reviewing some code that looks like this:
class A; // defined somewhere else, has both default constructor and A(int _int) defined
class B
{
public:
B(); // empty
A a;
};
int main()
{
B* b;
b = new B();
b->a(myInt); // here, calling the A(int _int) constructor,
//but default constructor should al...
I am currently working on an application that runs on several different Windows Mobile and CE devices. The project is written in unmanaged C++ using MFC. This application also comes with a supporting PC app and we programatically transfer files between the two through activesync/WMDC.
We have been running into many different issues be...