Hello, I have a struct like this
typedef struct bookStruct
{
char title[80];
char author[80];
} BookType;
And I have two strings like this
char *title = "A Book on C";
char *author = "A. Kelly";
Now I can't create a BookType like this
BookType book = {title, author};
Can anyone tell me what is wrong? How can I do that?
...
I have a class that has a vector of objects. What do I need to do to return one of this objects and change it outside the class, keeping the changings? Is it possible to do with regular pointers? Is there a standard procedure? (And yes, my background is in Java.)
...
Possible Duplicates:
What makes more sense - char* string or char *string?
Whats your preferred pointer declaration style, and why?
I've seen mixed versions of this in a lot of code. (This applies to C and C++, by the way.) People seem to declare pointers in one of two ways, and I have no idea which one is correct, of if it ...
I have a class with a vector of pointers to objects. I've introduced some elements on this vector, and on my main file I've managed to print them and add others with no problems. Now I'm trying to remove an element from that vector and check to see if it's not NULL but it is not working.
I'm filling it with on class Test:
Other *a = ne...
Possible Duplicate:
When pass-by-pointer is preferred to pass-by-reference in C++?
Hello everyone,
What do you consider a better programming practice: passing objects as pointers or references to functions.
What do you do for input validation?
Thanks.
...
Ok this time I decided to make a list using the STL. I need to create a dedicated TCP socket for each client. So everytime I've got a connection, I instantiate a socket and add a pointer to it on a list.
list<MyTcp*> SocketList; //This is the list of pointers to sockets
list<MyTcp*>::iterator it; //An iterator to the list of pointers ...
Hi,
The problem is the following:
On Windows x64, pointers are 64-bit, but type long is 32-bit.
MSVC doesn't seem to care, and even omits warnings about pointer truncation on the default warning level.
Since recently, there is a GCC that targets x86_64-w64-mingw32, or better native Windows x64. GCC produces errors when pointers are trun...
Having code:
int** a = new int*[2];
a[0] = new int(1);
a[1] = new int(2);
cout << "a[0] " << a[0] << '\n';
cout << "a[1] " << a[1] << '\n';
cout << "a[2] " << a[2] << '\n';
cout << "a[0] + 1 " << a[0] + 1 << '\n';//WHY THIS ISN'T == a[1] ?
cout << "*(a + 1): " << *(a + 1) << '\n'; //WHY THIS IS == a[1] ?
cout << "a[0] - a[1] " << stat...
I have a very simple test program, running on Solaris 5.8:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
char *paths;
paths = getenv("PATH");
printf("Paths: %s\n", paths);
free(paths); // this causes a bus error
return 0;
}
If I don't call free() at the end, it displays the message fine and exits. If I...
I have a function which takes a variable number of pointers, which I would like to modify. It looks something like:
void myPointerModifyingFunction (int num_args, ... ) {
void *gpu_pointer;
char mem_type;
va_list vl;
va_start(vl,num_args);
for (int i=0;i<num_args;i++) {
gpu_pointer=va_arg(vl,void*);
...
Assume I have a thread-safe collection of Things (call it a ThingList), and I want to add the following function.
Thing * ThingList::findByName(string name)
{
return &item[name]; // or something similar..
}
But by doing this, I've delegated the responsibility for thread safety to the calling code, which would have to do something li...
I have the following code:
int main() {
int n = 3, m = 4, a[n][m], i, j, (* p)[m] = a;
for (i = 0; i < n; i++)
for (j = 0; j < m; j++)
a[i][j] = 1;
p++;
(*p)[2] = 9;
return 0;
}
I have a hard time understanding what p is here, and the consequences of the operations on p in the end. Can someone g...
-(id)setBigObject:(BigObject *)abc{
self.wl = abc;
abc.smallObject = self.smallObject;
}
I have a abc, which is a big Object, when the user pass the bigObject, abc. I assign to my wl value, so , I write "self.wl = abc;", but I want my smallObject assign to the abc's smallObject, so, I do "abc.smallObject = self.smallObject; ...
char *a[]={"diamonds","clubs","spades","hearts"};
char **p[]={a+3,a+2,a+1,a};
char ***ptr=p;
cout<<*ptr[2][2];
why does it display h and please explain how is the 2d array of ptr implementing and its elements
...
Hello,
Hopefully my title was descriptive enough to attract the right help.
I want to write a function that will return 1 thing, and modify a provided pointer in another.
My current function declaration is . . .
char * replaceURLS(char * body)
What I want to do is copy all of body's data into a new string, and set body to point to ...
I am manipulating vectors of objects defined as follow:
class Hyp{
public:
int x;
int y;
double wFactor;
double hFactor;
char shapeNum;
double* visibleShape;
int xmin, xmax, ymin, ymax;
Hyp(int xx, int yy, double ww, double hh, char s): x(xx), y(yy), wFactor(ww), hFactor(hh), shapeNum(s) {visibleShape=0;shapeNum=-1;};
//Copy constru...
Not sure why I'm getting this error. I have the following:
int* arr = new int[25];
int* foo(){
int* i;
cout << "Enter an integer:";
cin >> *i;
return i;
}
void test(int** myInt){
*myInt = foo();
}
This call here is where I get the error:
test(arr[0]); //here i get invalid conversion from int to int**
...
I am trying to write a function to get a string from uart. Its for an embedded system so I don't want to use malloc.
The pointer that is passed to the getstring function seems to point to garbage after the gets_e_uart1() is called. I don't use pointers too often so I'm sure it is something really stupid and trivial that Im doing wrong.
...
I keep getting a segmentation fault when the readAuthor() method is called. Does anybody know why this happens? I am supposed to use dynamic arrays, I know this would be so easy if I was using static array.
#include <iostream>
#include <string>
#include <cstring>
#include <cstdlib>
using namespace std;
/** declare arrays **/
int* isbn...
hello.
I implemented reference counting pointers (called SP in the example) and im having problems with polymorphism which i think i shouldn't have.
In the following code:
SP<BaseClass> foo()
{
// Some logic...
SP<DerivedClass> retPtr = new DerivedClass();
return retPtr;
}
DerivedClass inherits f...