So I decided to dwelve a bit within the pesty C++.
When I call the delete function on a pointer to a simple class that I created I'm greeted by a Debug Assertion Failure -Expression:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse). I assume this is because I've handled the string manipulation wrong and thus causing memory corruption.
I created ...
Hi,
I'm trying to write two simple macros for begin and end of functions in order to manage and log all the Exceptions in my program. In other words, I wanna have a try-catch block in all of my functions.
in simple case consider the following macros.
#define __BEGIN_FUNCTION__ try {
#define __END_FUNCTION__ } catch(std::exception e) \...
I'm moving from Java to C++ and am a bit confused of the language's flexibility. One point is that there are three ways to store objects: A pointer, a reference and a scalar (storing the object itself if I understand it correctly).
I tend to use references where possible, because that is as close to Java as possible. In some cases, e.g....
I am trying to create a Stream_Handle for a harddisk device. Here is the piece of code.
ntStatus = NtCreateFile(source, DesiredAccess, &oa, &ios, NULL, FileAttributes, ShareAccess,
CreateDisposition, CreateOptions, NULL, 0);
//Create ReadStream
boost::asio::io_service io_service;
boost::asio::windows::stream_handle...
i have function to implement memcpy function
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
char *memcpy(char *dest,char *src,int n){
char *ch=dest;
while (n--)
*ch++=*src++;
return dest;
}
int main(){
char *src="georgia";
int n=strlen(src);
char *dest=new ch...
I have defined a class in C++ which holds an array of scalars of type T for which I want to define operators like sin, cos, etc. For defining the meaning of sin applied on an object of this class I need to know the meaning of sin applied on the single scalar type T. This means I need to use appropriate math libraries (corresponding to th...
hello
Does C++ standard guarantee the following?:
template<typename T>
void function(T (&)[1]);
template<typename T>
void function(T*);
int a[1];
function(a); // first function gets called, not second version
...
I have the following code snippet:
std::vector< boost::shared_ptr<Foo> >::iterator it;
it = returnsAnIterator();
// often, it will point to a shared_ptr that is NULL, and I want to test for that
if(*it)
{
// do stuff
}
else // do other stuff
Am I testing correctly? The boost docs say that a shared_ptr can be implicitly converted ...
Browsing through a Currency in C++0x book and thought I would give the sample code a run. It is as basic as it gets.
#include <iostream>
#include <thread>
void hello()
{
std::cout<<"Hello Concurrent World\n";
}
int main(int argc, char *argv[])
{
std::thread t(hello);
t.join();
}
Compiled with:
g++ -std=c++0x -g -o pg...
Hi, I'm having difficulties registering an example XPCOM component into firefox from this example here: http://www.iosart.com/firefox/xpcom/
I'm trying this on Firefox 3.6. After successfully building and transferring the XPT and library into the components folder in firefox, and following what instructions are applicable, I'm unable to ...
I have something like this in my code:
template <typename T>
struct A
{
void Print();
};
template <>
struct A<char*>
{
void Print() { printf("Char*!\n"); }
};
template <typename T>
void DoSomething(T& lol)
{
A<T> a;
a.Print();
}
int main()
{
char a[5];
DoSomething(a);
}
And this produces the following linker error:
err...
Hey there,
I'm working on a small project trying to integrate lua with c++.
My problem however is as follows:
I have multiple lua scripts, lets call them s1.lua s2.lua and s3.lua. Each of these has the following functions: setVars() and executeResults().
Now I am able to to call a lua file through LuaL_dofile and immediately after use...
Possible Duplicate:
What are the differences between struct and class in C++
what is the practical difference between class and struct in c++ except the default definition of members to be public (in struct) and private (in class)?
if this is the only difference why do we need both?
...
im using visual studio c++ 2008 i created project that contents the full window code. i don't know how to output text to window. i mean i have full functional window with menu bar and under the menu bar there is the body im trying to ouput the text in the body but how?
...
It is always better for contants such as PI to #define them or declare them const so the compiler can optimize and it becomes less error prone. I was wondering however, how are literal numbers in statements treated? Ex:
float x;
const int y = 60;
x = y / 3.0f;
In this example how would 3.0f be treated? Would it inherit the optimizatio...
Would it be possible for a public function to return a pointer to a private variable in the class. If so / if not, what would happen? would it crash or is there anything highly unsafe about this? Can the pointed data be read or written to?
Thanks
...
My problem is quite simple. I want the following macro
#define PROXYPASS(name, param) \
void MyClass::sl_name(param _param) { \
emit name(_param); \
}
to expand PROXYPASS(clientAdded, Client*) to:
void MyClass::sl_clientAdded(Client* _param) { \
emit clientAdded(_param); \
}
but since it ain't working i.e. it still shows ju...
EDIT: I should've mentioned, I was looking at the documentation for Boost's ptr_sequence_adapter and it claims that their adapter for template< class U > void push_back( ::std::auto_ptr<U> x ); is equivalent to doing vec.push_back(autoPtr.release()); and also provides the strong exception guarantee. And then I realized I was confusing t...
is there any method to remove the duplicate elements in an array in place in C/C++ in 0(n)?
Suppose elements are a[5]={1,2,2,3,4}
then resulting array should contain {1,2,3,4}
the solution can be achieved using two for loops but that would involve O(n^2) i believe.
...
I've developed an application in Qt which uses a launch script, myapp.sh. I've created a .desktop file which launches this script, and set:
Command: $PWD/myapp.sh
Work path: $PWD
However, $PWD prints my home directory when I launch the .desktop file, resulting in attempting to launch ~/myapp.sh rather than ~/Development/build-director...