My question is not about calling a virtual member function from a base class constructor, but whether the pointer to a virtual member function is valid in the base class constructor.
Given the following
class A
{
void (A::*m_pMember)();
public:
A() :
m_pMember(&A::vmember)
{
}
virtual void vmember()
{
...
I have some code to interface Python to C++ which works fine but every time I look at it I think there must be a better way to do it. On the C++ side there is a 'variant' type that can deal with a fixed range of basic types - int, real, string, vector of variants, etc. I have some code using the Python API to convert from the equivalen...
Possible Duplicates:
Unique random numbers in O(1)?
How do you efficiently generate a list of K non-repeating integers between 0 and an upper bound N
I want to generate random number in a certain diapason, and I must be sure, that each new number is not a duplicate of formers. One solution is to store formerly generated numb...
I have several flag-like enumerations, in C++. For example:
enum some_state {
state_normal = 1 << 0,
state_special = 1 << 1,
state_somethingelse = 1 << 2,
state_none = 0,
};
some_state var1;
Now on using bit operators like & or |, I get compilers errors. I know I can overload operator | et.al. for enums, ...
I recently found a interesting behaviour of g++ when compared with MSVC++ 2008. Consider this tiny program:
#include <cstdlib>
const int ARR_LENGTH = 512;
void doSomething( int iLen );
int main( int argc, char** argv )
{
doSomething( ARR_LENGTH );
return 0;
}
void doSomething( int iLen )
{
int iTest[iLen];
return;
}
...
This is driving me crazy:
I have function
void gst_init(int *argc, char **argv[]);
in the gstreamer api and I want to call it with some parameters I define, like:
int argc = 2;
char* argv[2] = {"myvalue1", "myvalue2"};
gst_init(&argc, &argv);
This code doesn't compile (I get error C2664):
error C2664: 'gst_init' : cannot convert...
Hey guys,
I have been having a few issues implementing my narrow phase collision detection. Broadphase is working perfectly.
I have a group of polygons, that have a stl::vector array of points for their vertices in clockwise order. Every cycle, I check to see whether they're colliding.
I have borrowed the following Point in Polygon ...
I am new to C++ and I would like to know how can I do a simple program where some functions are available.
For example:
mypg.exe function1 string1
mypg.exe function1 textfile1
Takes the text from the str/file and shows or prints.
And then:
mypg.exe function2 string1
mypg.exe function2 textfile1
Uses the text for a different thing...
Say I have a function:
void someFunc(int *x,int count);
which is out of my control, so I can't write it to accept iterators.
Is it safe to call it like so (regardless of the specific STL implementation):
vector<int> v;
/* ... */
someFunc(&v[0],v.size());
Obviously, one counter example is vector<bool>. How about any other type? (as...
I have a huge MMC snapin written in Visual C++ 9. Every once in a while when I hit F5 in MMC mmc.exe crashes. If I attach a debugger to it I see the following message:
A buffer overrun has occurred in mmc.exe which has corrupted the program's internal state. Press Break to debug the program or Continue to terminate the program.
...
I need a way to traverse a binary tree, using multiple threads and store elements that matches a criteria into a list.
How do I do that, in a thread safe way?
...
while going through some of the mili source code I came across a struct declared like this:
template <class T, class Pre, class Pos>
struct PrePosCaller<T*, Pre, Pos>
(from here)
The part I'm unfamiliar with is <T*, Pre, Pos>. I understand what the code does and its purpose in this context but I would like to know where it is documen...
Is there any particular reason that multi-line string literals such as the following are not permitted in C++?
string script =
"
Some
Formatted
String Literal
";
I know that multi-line string literals may be created by putting a backslash before each newline.
I am writing a programming language (similar to C) and would like ...
When you have a piece of software that runs an out of process COM server and the COM server crashes, will it show a message (let's say its an unhandled exception) to the user or what will happen?
Also, will the COM client crash too, knowing that this client relies on this COM Server quite a lot?
What's the behaviour in regards COM Serv...
Hi, I am using NetBeans IDE 6.8 to create C++ project. While I use class inheritance, however, it seems to me that it does not recognize the derived class. Here is what I have:
class A
{
public:
A(vector<double> a, double b) {...}
};
class B : public A
{
public:
additionalfunction(...) {...}
};
main()
{
vector<double> c = ...
Assuming the stream extraction won't fail, will this
if( !(stream >> token) )
throw runtime_error( "Unexpected end of recipe." );
else if( token == "something" )
// do something
else
throw runtime_error( "Unknown token" );
Work like this
if( !(stream >> token) )
throw std::runtime_error( "Unexpected end of recipe." );...
in c++ ..
first of all I need to make a constructor of class Date d() that creates the current date.. what should i do?
after that i have a problem with this program:
class Noleggio
{
public:
//Noleggio(unsigned f, unsigned n, unsigned c) : inizio() { film = f; copia = n; cliente = c; restituito = false; }
bool restituito;...
Suppose I have the following two data structures:
std::vector<int> all_items;
std::set<int> bad_items;
The all_items vector contains all known items and the bad_items vector contains a list of bad items. These two data structures are populated entirely independent of one another.
What's the proper way to write a method that will retu...
How can I get Visual Studio to help me optimize my application, or tell me areas of slowness? Thanks
...
I've got a DLL that I've created as a C++ Win32 application. To prevent name mangling in my DLL, I have used the EXPORT definition defined below:
#ifndef EXPORT
#define EXPORT extern "C" __declspec(dllexport)
#endif
EXPORT int _stdcall SteadyFor(double Par[], double Inlet[], double Outlet[]);
To get this code to compile, I had to go ...