Edit1: I realize this is hard to understand this question without having an insight of what I'm trying to do. The class A is not complete but it essentially stand for a C-array "proxy" (or "viewer" or "sampler"). One interesting usage is too present a C-array as a 2d grid (the relevant function are not shown here). The property of this c...
When trying to get the value of a boost::optional object, BOOST_ASSERT is used to make sure the object is indeed initialized.
But what I would like when dereferencing an uninitialized optional is for an exception to be thrown - is there any way to get this behaviour in a release build? If not, is there any other similar library which h...
Hello, I'm trying to obtain my local (not the external) IP address using the getaddrinfo() function, but I saw the examples provided here, and they where too complex for my needs. Also saw other posts and most of them really wanted to get the external IP, not the local one.
Could anyone provide a link to a simple example (or a simple ex...
In C++ a pointer is a pointer to an address of memory where another variable is stored and in C# a reference is some how same. What is the difference between these two?
...
I know that .h file is supposed to have:
class declarations,
function prototypes,
and extern variables (for global variables)
But is there some significance of making it a .h file?
I tried renaming my .h file to a .c file and it still works.
We can name our file to be anything, but we choose to name it as a .h file.
Am I correct?
...
I have a User GUID. How could I get the Organizational Unit (OU) of this user?
...
Hello, I'm pretty sure that this question is very noob but I'm not used to C++.
I have a .hpp for class definition and a .cpp for class implementation. I have some private instances on the class, for example:
class Test
{
Test(void);
private:
SomeClass anInstance;
};
To create the instance and call the constructor do...
I want to jump from the middle of a switch statement, to the loop statement in the following code:
while (something = get_something())
{
switch (something)
{
case A:
case B:
break;
default:
// get another something and try again
continue;
}
// do something for a handled something
d...
I am looking for methods to generate random strings in C++.Here is my code:
string randomStrGen(int length) {
static string charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
string result;
result.resize(length);
srand(time(NULL));
for (int i = 0; i < length; i++)
result[i] = charset...
When can an object of a class call the destructor of that class, as if it's a regular function? Why can't it call the constructor of the same class, as one of its regular functions? Why does the compiler stops us from doing this?
For example:
class c
{
public:
void add() ;
c();
~c() ;
};
void main()
{
c objC ;
objC.add() ;...
My program was:-
#include < iostream.h>
#include < conio.h>
struct base
{
protected:
void get()
{
cin>>a>>b;
}
public:
base(int i=0, int j=0);
void put()
{
cout << a << '\t' << b << "\tput 1";
}
int a,b,c;
~base()
{
cout << "base destroyed";
}
};
class der...
Is there a tool that would go through a list of files and would spit out a header file with forward declarations of classes it encounters? Ideally, I would like to integrate it into Visual C++'s build process.
...
I have been developing a project that I absolutely must develop part-way in C++. I need develop a wrapper and expose some C++ functionality into my C# app. I have been a C# engineer since the near-beginning of .NET, and have had very little experience in C++. It still looks very foreign to me when attempting to understand the syntax.
...
Are there any downsides with using make_shared<T>() instead of using shared_ptr<T>(new T).
Boost documentation states
There have been repeated requests from
users for a factory function that
creates an object of a given type and
returns a shared_ptr to it. Besides
convenience and style, such a function
is also exception s...
Well, after solving this problem by naive STL set,I was reading the forum entries,there I find this entry :
#include <iostream>
#include <cmath>
#define MAX 100
using namespace std;
int main(){
int res=(MAX-1)*(MAX-1);
for(int i=2;i<MAX;i++)
for(int j=i*i;j<=MAX;j=j*i)
res = res-int(MAX*(log(i)/log(...
Hello,
I have created a Timer class that must call a callback method when the timer has expired. Currently I have it working with normal function pointers (they are declared as void (*)(void), when the Elapsed event happens the function pointer is called.
Is possible to do the same thing with a member function that has also the signat...
Hi there,
I'm including python.h in my VC++ dll project which causes an implicit linking with python25.dll.
However I want to load a specific python25.dll (several can be present on the computer) so I created a very simple manifest file named test.manifest:
<?xml version='1.0' encoding='UTF-8' standalone='yes'?>
<assembly xmlns='urn:sc...
Hi,
EDIT: Thanks for the answers so far, at least I can compile it now, but I still get a segmentation error.
For compilation I use the following line:
gcc -g -O0 -I../include -L../ test.c -static -lrt
Source Code is as follows:
#include <sys/time.h>
#include <time.h>
#include <stdio.h>
struct timespec *diff(struct timespec *start...
I created the following two C++ files:
Stack.cpp
#include<iostream>
using namespace std;
const int MaxStack = 10000;
const char EmptyFlag = '\0';
class Stack {
char items[MaxStack];
int top;
public:
enum { FullStack = MaxStack, EmptyStack = -1 };
enum { False = 0, True = 1};
// methods
void init();
void ...
I build a paralle sum code to sum a large number of float numbers then I found when the number of figures is bigger than 100000000, the result will go wrong. Then I build a serial code to compare. The serial code also get wrong number. Anybody knows why? Thanks!
my simple code is as follows.
the result is " 1.67772e+007". It should be ...