I saw this piece of C# code in one of the msdn articles:
using System; class Test
{
public static unsafe void Main()
{
int* fib = stackalloc int[100];
int* p = fib;
*p++ = *p++ = 1;
for (int i=2; i<100; ++i, ++p)
*p = p[-1] + p[-2];
for (int i=0; i<10; ++i)
Console.WriteLine (fib[i...
This is a question from an exam in an advanced course in OOP, taught in C++ (in TAU university, this semester):
Q: What is the difference between a C++ pointer and a reference?
A. A reference is the entire object while a pointer is only the address of it.
B. The same meaning, and difference is only in syntax and usage.
C. The sy...
I've been trying to get this to work for a good few hours now, but I can't seem to get my head around it.
I'm trying to write a function that is able to return an array of strings.
#include <stdio.h>
#include <stdlib.h>
/**
* This is just a test, error checking ommited
*/
int FillArray( char *** Data );
int main()
{
char ** Da...
I passed a pointer ptr to a function whose prototype takes it as const.
foo( const char *str );
Which according to my understanding means that it will not be able to change the contents of ptr passed. Like in the case of foo( const int i ). If foo() tries to chnage the value of i, compiler gives error.
But here I see that it can cha...
Possible Duplicate:
What is the point of function pointers?
How pointer function work, and where is the difference ( not abstract like encapsulatin ) from methods
...
In the big picture I want to create a frame based application in Bada that has a single UI control - a label. So far so good, but I want it to display a number of my choosing and decrement it repeatedly every X seconds. The threading is fine (I think), but I can't pass the label pointer as a class variable.
//MyTask.h
//...
result Con...
The title says it all.
Example:
bool isHeapPtr(void* ptr)
{
//...
}
int iStack = 35;
int *ptrStack = &iStack;
bool isHeapPointer1 = isHeapPtr(ptrStack); // Should be false
bool isHeapPointer2 = isHeapPtr(new int(5)); // Should be true
/* I know... it is a memory leak */
Why, I want to know this:
If I have in a class a member-p...
Is this the correct syntax for passing a file pointer by reference?
Function call: printNew(&fpt);
printNew(FILE **fpt)
{
//change to fpt in here kept after function exits?
}
Thanks.
...
Can you set any index of array as starting index i.e where to read from file? I was afraid if the buffer might get corrupted in the process.
#include <stdio.h>
int main()
{
FILE *f = fopen("C:\\dummy.txt", "rt");
char lines[30]; //large enough array depending on file size
fpos_t index = 0;
while(fgets(&lines[index], ...
Hi experts,
Here is the context of the code:
void THREAD_CC server_thread(void *arg)
{
BIO *client = (BIO *)arg;
...
}
Does the expression (BIO *)arg transform the void pointer arg into a pointer that points to BIO? I'm not sure if I got this right or not.
Any help would be much appreciated!
Z.Zen
...
If a pointer to an user defined type is passed as template argument to a template class, is it possible to get the class type of the argument?
template <class T> struct UserType {
typedef T value_type;
...
};
int main () {
typedef std::vector<UserType<double>*> vecType
vecType vec;
vecType::value_type::value_type m...
I'm trying to understand how pointers to statically allocated objects work and where they can go wrong.
I wrote this code:
int* pinf = NULL;
for (int i = 0; i<1;i++) {
int inf = 4;
pinf = &inf;
}
cout<<"inf"<< (*pinf)<<endl;
I was surprised that it worked becasue I thought that inf would dissapear when the program left the b...
Suppose I have a simple class in Scala:
class Simple {
def doit(a: String): Int = 42
}
How can I store in a val the Function2[Simple, String, Int] that takes two arguments (the target Simple object, the String argument), and can call doit() get me the result back?
...
Hi,
simple question, I import a DLL function and the parameter are int*.
When I try to enter Method(0), I get an error which says: "int and int* can not convert".
What is that meaning?
...
Background: I am receiving a array as char* as a part of socket session. Now we have to match the Tokens (HTTP headers) out of it.Code here is that we have created a UBYTE* and getting the value from the char array after typecasting with UBYTE. Later same UBYTE pointer we are passing to other function which accepts char* after typecastin...
I'm having a problem with a couple of event handler classes I'm trying to write. Basically, the idea is to have an event handler class for each logical group of objects. In most cases, the events are between objects and their handler, but in some cases events are also sent between handler objects as well.
I've written the code such that...
Hi there,
I used the following piece of code to read data from files as part of a larger program.
double data_read(FILE *stream,int code) {
char data[8];
switch(code) {
case 0x08:
return (unsigned char)fgetc(stream);
case 0x09:
return (signed char)fgetc(stream);
case 0x0b:...
How to write this in another (perhaps shorter) way?
Is there a better way to initialize an allocated array in C++?
int main(void) {
int* a;
a = new int[10];
for (int i=0; i < 10; ++i) a[i] = 0;
}
...
Hi,
something strange is happening to my code. I am using a library which is supposed to work perfectly (nglib from the open-source Netgen mesher). I can link and include everything, but I cannot use this library :
The object I want to use is Ng_Mesh* mesh = Ng_NewMesh ();
The Ng_NewMesh() method is :
DLL_HEADER Ng_Mesh * Ng_NewM...
Given:
MY_CLASS* ptr = MY_CLASS::GetSomeInstance();
What is the correct way to output ptr to std::cerr, so I can log its value? Note I don't want to write the class, just the address.
...