In the problems of inline functions in wikipedia :
http://en.wikipedia.org/wiki/Inline%5Fexpansion#Problems
it says : "# A language specification may allow a program to make additional assumptions about arguments to procedures that it can no longer make after the procedure is inlined."
Could somebody elaborate this point?
How do you p...
I have a class that uses an "add-on" template to add additional functionality as below:
template< class T >
class AddOn_A
{
public:
int SomeFuncA()
{
T* pT = static_cast< T* >( this );
return pT->DoSomething() + 1;
};
};
class CMyClass : public AddOn_A< CMyClass >
{
public:
int DoSomething()
{
...
I have a multithreaded C++ application which holds a complex data structure in memory (cached data).
Everything is great while I just read the data. I can have as many threads as I want access the data.
However the cached structure is not static.
If the requested data item is not available it will be read from database and is then in...
I have some code which I need to code in C++ due to heavy reliance on templates. I want to call this code from MATLAB: basically, I need to pass some parameters to the C++ code, and have the C++ code return a matrix to MATLAB. I have heard this is possible with something called a MEX file which I am still looking into. However I am not s...
Vector(const Vector& other) // Copy constructor
{
x = other.x;
y = other.y;
Why is the argument a const?
...
Asynchronous operations with I/O Completion Ports return 0 bytes transferred, although the I/O operations work as expected (my read buffers become full).
BYTE buffer[1024] = {0};
OVERLAPPED o = {0};
HANDLE file = CreateFile(
_T("hello.txt"),
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED...
Hi guys,
i have a little problem on writing the string into a file,
How can i write the string into the file and able to view it as ascii text?
because i am able to do that when i set the default value for str but not when i enter a str data
Thanks.
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
int main...
So, I like vectors a lot. They're nifty and fast. But I know this thing called a valarray exists. Why would I use a valarray instead of a vector? I know valarrays have some syntactic sugar, but other than that, when are they useful?
...
I have been using Visual Studio 2005 under Windows XP Pro 64-bit for C and C++ projects for a while. One of the popular tricks I have been using from time to time in the debugger was to remember a numeric pointer value from the previous debugging run of the program (say 0x00000000FFAB8938), add it to watch window with a proper typecast (...
Hello,
I have std::strings containing numbers in the leading section that I need to sort. The numbers can be integers or floats.
The vector<std::string> sort was not optimal, I found the following natural sort program which was much better. I still have a small issue with numbers smaller than zero that do not sort just right. Does anyo...
Hello everyone,
I'm trying to obtain the top say, 100 scores from a list of scores being generated by my program. Unfortuatly the list is huge (on the order of millions to billions) so sorting is a time intensive portion of the program.
Whats the best way of doing the sorting to get the top 100 scores?
The only two methods i can th...
I have a decorator-like pattern with a base that requires a constructor parameter. The decorator is constructed such that it can take an arbitrary number of add-on components as template parameters (up to 3 in this example).
Unfortunately, I can't figure out how to pass the base's constructor parameter to it when more than one add-on is...
I'm trying to work through ways to create a class with a std::string argument, but which also handles NULL without throwing an exception. Here's an example of the code:
class myString {
public:
myString(const std::string& str) : _str(str) {}
std::string _str;
};
int main() {
myString mystr(NULL);
printf("mystr = <%s>\n...
Hi,
In Xcode 3.2.1 on Mac OS X Snow Leopard, I open a project under:
Command Line Tool of type C++ stdc++.
I have the following simple code:
#include <iostream>
#include <string>
using namespace std;
int main(){
string myvar;
cout << "Enter something: " << endl;
cin >> myvar;
cout << endl << myvar << endl;
retu...
What is the difference between including a file from a header file or from a source file in C++ in regards to performance during compilation?
What are the reasons to include files in the source file and not in the header file (except when absolutely required)?
Does the one (header) affect compile time and the other (source file) affect...
I tried to allocate 17338896 elements of floating point numbers as follows (which is roughly 70 mb):
state = cublasAlloc(theSim->Ndim*theSim->Ndim,
sizeof(*(theSim->K0)),
(void**)&K0cuda);
if(state != CUBLAS_STATUS_SUCCESS) {
printf("Error allocation video memory.\n");
return -1;
...
Hello
I have a exported function in a c++ DLL
// C++ DLL (Blarggg.dll)
extern "C"
{
USHORT ReadProperty( BYTE * messsage, USHORT length, BYTE * invokeID )
{
if( invokeID != NULL ) {
* invokeID = 10 ;
}
return 0;
}
}
That I would like to make it available to my C# application
/...
In another question, the answer states that on Unixes with /proc, the really straight and reliable way is to readlink("/proc/self/exe", buf, bufsize) and it then proceeds to give backup solutions as follows:
On Unixes without /proc (i.e. if above fails):
If argv[0] starts with "/" (absolute path) this is the path.
Otherwise if argv[0]...
What is the size of virtual pointer(VPTR) for a virtual table in C++? Also this is not a homework question...just a question that came to my mind while I was reading a C++ book.
...
I have neved did a cross platform development before but the process we currently employ such as doing the development on a Windows machine (as we are mostly a Windows shop) and then actually building the binaries on a Solaris box looks a bit convoluted to me.
Can you recomend me a cross compiler so I can limit development tasks to a Wi...