In C++, when you have a function that takes a reference to an object, how can you pass an object pointer to it?
As so:
Myobject * obj = new Myobject();
somefunc(obj); //-> Does not work?? Illegal cast??
somefunc(Myobject& b)
{
// Do something
}
...
Declarations of auto_ptr from C++ Standard Library
namespace std {
template <class Y> struct auto_ptr_ref {};
template <class X>
class auto_ptr {
public:
typedef X element_type;
// 20.4.5.1 construct/copy/destroy:
explicit auto_ptr(X* p =0) throw();
auto_ptr(auto_ptr&) throw();
templa...
I am using Visual Studio 2010 to make a 3D model in C++ and OpenGL. I started a project on my home pc, and then decided to put it in a repository, so that I could get the code for development on my laptop and not have to keep transferring files between the two computers (and also just to get some practice at using source control).
The p...
Why can I not do this:
char* p = new char[10];
void SetString(char * const str)
{
p = str;
}
SetString("Hello");
I have a const pointer to a char, why can I not assign the const pointer to another pointer?
It just seems illogical, as by assigning it to another pointer, you are not essentially violating the const-ness of the ch...
Hi,
I have a function named _push which can handle different parameters, including tuples, and is supposed to return the number of pushed elements.
For example, _push(5) should push '5' on the stack (the stack of lua) and return 1 (because one value was pushed), while _push(std::make_tuple(5, "hello")) should push '5' and 'hello' and r...
Hello. I am writing a full-screen 3D game and I have created a menu in which the user may select the screen resolution to match his hardware capacity.
I am enumerating all the available screen modes with EnumDisplaySettingsExA like this :
std::vector<DEVMODEA> modes;
DEVMODEA modeInfo;
int modeNum = -1;
while (EnumDispl...
In Windows with cl.exe ,
warning format is d:\path\Hello.cpp:131:2: <...>
error format is d:\path\Hello.cpp(694) : <...>
Somehow, qt-creator parses and shows these errors but does not open the file when clicked:
File not found.
I tried every toolchain creator 2.0 offers.
I'm using jam and had to manually redirect 2>&1 stdout to stde...
I was taking a look at the assert() reference page and I got stuck while I read the given example:
/* assert example */
#include <stdio.h>
#include <assert.h>
int main ()
{
FILE * datafile;
datafile=fopen ("file.dat","r");
assert (datafile);
fclose (datafile);
return 0;
}
In this example, assert is used to abort the pr...
I use QGraphicsiew and QGraphicsScene in order to draw graphics. How can I organize zoom-in and zoom-out (during zooming in scrolls should appear and while zooming out scrolls should disappear)?
...
is there a way to implement such a communication in C++?
use case:
my main program calls a function of my external library to process a list. every time the function iterates through the list it sends a ping to the caller. the latter uses the received signal to track progress of the former and sends back a boolean pong [true: okay, mov...
pthread_rwlock t1;
pthread_rwlock_wrlock(&t1);
pthread_rwlock t2 = t1;
what happend?
is t2 locked or not?
...
Hi,
I want to use clone to log the current status of my program.
It has a lot of loops and I want to keep track of the process without printing the status in each loop iteration.
That's why I created this proof-of-concept:
#include <iostream>
#include <cstdlib>
unsigned int i;
int log(void*) {
std::cout << "LOGGING START" << std::...
Is there any way to force Clean action as a Post / Pre build event for single project in Visual Studio?
Thank you.
...
I was going through this link Will it optimize and wondered how can we know what optimizations are done by a particular compiler.
Like does VC8.0 convert if-else statements to switch-case?
Is such information available on msdn?
...
i need some idea for creatin a encryption program can any one help!?
i need to create the program in java or c++ so need to create a logic for it
this encryption prog should automatically encrypt the document n should decrypt it only if the givien conditions such as the password are fulfilled !
plz help !
...
I'm getting the following warning
warning C4996: 'std::_Uninitialized_copy0': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators' c:\program fi...
Hi,
I'm trying to use qFromBigEndian to read a 32-bit int from a byte stream received over a udp socket.
void processData(uchar *data)
{
qint32 addr;
addr = qFromBigEndian(data);
}
Compiling this gives the following error:
error: invalid conversion from 'uchar*' to 'qint32'
The Qt documentation says:
T qFromBigEndian ( const...
I want to write a generic (C/C++) library that I will use to develop daemons in the Linux environment. Rather than reinventing the wheel, I thought I'd come in here to find out if there are any well known libraries in use.
The library could be either C or C++ - although I would prefer C++ (maybe something that was part of, or based on t...
Hello, I'm using boost (signals + bind) and c++ for passing function reference. Here is the code:
#define CONNECT(FunctionPointer) \
connect(bind(FunctionPointer, this, _1));
I use this like this:
class SomeClass {
void test1() {}
void test2(int someArg) {}
SomeClass() {
CONNECT(&SomeClass::test1);
CONNECT(&S...
To think ... there I have been happily programming in an MFC riddled environment for years, using ASSERT() whenever it seemed OK and just today I (was) stumbled upon the VERIFY Macro:
http://msdn.microsoft.com/en-us/library/fcatwy09%28v=VS.71%29.aspx
It's basically the same as ASSERT() except the expression will not be removed in releas...