Option 1:
class B{//};
class A
{
public:
void Funcs();
private:
std::vector<A> vecA;
};
Option2:
class B{//};
class A
{
public:
void Funcs();
private:
std::vector<A*> vecpA;
};
Which one is better, is there any guidelines?
...
I understand that I can point to number of vectors std::vector<int> using for loop on one vector<int*> onev_point_2_all etc.. but how do i do that using iterators is there a way of creating a vector of iterators instead of a vector of pointers ?
...
hello,
when i use vector to store some data, i usually access to this data by the pointer of the vector's first entry. because it it faster than the at() method. but i realize that when i insert a block of data, say an array to the end of vector, the first entry's pointer changes. this may be realated to stack stuff, but if i add the ar...
Hello!
I'm making a network sniffer for my college project using the libpcap library. Majority of the code works without any problem, however, I'm stuck with the following issue. I've added five command line options using getopt_long() function, but one option doesn't work as expected.
The option is -d (--device_info) and is used to pri...
Hi all,
(I am coding in C#)
I want to pass a pointer to structure through an API.
Say structure is,
[StructLayout(LayoutKind.Sequential,CharSet= CharSet.Ansi)]
public struct PassThisStruct
{
public Int32 Param1;
public Int32 Param2;
[MarshalAs(UnmanagedType.ByValArray, SizeConst=13)]
...
I have a problem returning an object that was created in other thread.
The situation is this, my app need to send some request to remote server and wait an answer.
In the main thread (1) i have a method called SendAndWait. This method put a message in a message queue for be sent and wait for an answer.
Another thread (2) send the message...
I've got a simple class called object that I'm having a problem with. Theres one method which causes a segfault if I call it. I don't understand why.
typedef class object
{
private:
short id;
std::string name;
SDL_Rect offset;
public:
object();
object(short i, std::string n);
~object();
o...
Suppose I have the following code:
typedef struct
{
char **p;
} STRUCT;
int main()
{
STRUCT s;
*(s.p) = "hello";
printf("%s\n", *(s.p));
return 0;
}
which obviously doesn't work, but it should show what I want to do. How would I go about initialising, accessing, printing, etc the array of strings in the structure...
Hi, right now I'm trying to teach someone about C programming. Specifically right now we're on pointers in C. However I feel this is a difficult concept to explain, as the person I'm teaching doesn't have much programming experience. I was wondering if anybody knew of a good tutorial on C pointers for a true beginner programmer?
I've tr...
1) if(null != parentObj.childObj)
2) if(parentObj.childObj != null)
Do you think that "1" will avoid a potential null pointer exception in the case where 'parentObj' is null, in contrast to "2"?
...
So, when I pass a const char * to a function once, can I use it again? It appears to end up spitting out crap to me.
const char *config_file = "file.txt";
function(int x, config_file);
cout << "Number" << x;
secondfunction(int y, config_file);
Do I need to make another pointer to config_file?
If so, how do I do that?
Thanks!
...
What do I need to change here so that animal contains {3,4}?
void funct(unsigned char *elf)
{
unsigned char fish[2]={3,4};
elf=fish;
}
int main()
{
unsigned char animal[2]={1,2};
funct(animal);
return 0;
}
EDIT: I see memcpy is an option. Is there another way just manipulating pointers?
...
this is the rough idea of what I am trying to do:
I want the pointer in main to point to the word I just in my function.
my actual code is very long so please excuse this format.
main()
{
char *word;
int lim 256;
*word = function(word,lim)//I am not returning the address back only the first letter
}
function(word,lim)
{
//memory allo...
Hey, so lets say I get a file as the first command line argument.
int main(int argc, char** argv) {
unsigned char* fileArray;
FILE* file1 = fopen(argv[1], "r");
}
Now how can I go about reading that file, char by char, into the char* fileArray?
Basically how can I convert a FILE* to a char* before I know how big I need to ma...
Hi,
I have a 2d array of a class. The size of array is very large (around 3000*3000) and accessing the array with ordinary row and column method is taking very much time. For this purpose, I want to use pointers to access the array.
Following is my array code:
Class definition:
Class BoxData
{
Size _bound;
bool _isFilled=fa...
I have a struct which is a node, and another which is a list of these nodes. In the list struct, its an array of nodes, but instead of an array, it's a pointer to pointer with a size integer:
typedef struct node {
struct node *next;
MyDef *entry;
} Node;
typedef struct list {
Node **table;
int size;
} List;
List *init...
Just trying to make a kind of hash table with each node being a linked list.
Having trouble just initializing the space, what am I doing wrong?
#include <stdlib.h>
typedef struct entry {
struct entry *next;
void *theData;
} Entry;
typedef struct HashTable {
Entry **table;
int size;
} HashTable;
int main(){
HashTable *ml;
ml =...
hello
i am having a trouble in taking input for the character type in c.the behavior of my source code is unusual.
my code is:
int n,i;
char *ps;
printf("Total no:");
scanf("%d",&n);
ps=(char *)calloc(n,sizeof(char));
for(i=0;i<n;i++) {
printf("Enter character %d:",i+1);
scanf("%c",ps+i);
}
then as per my requirement it...
Possible Duplicates:
Where can I learn more about pointers?
The Definitive C Book Guide and List
Can anyone suggest me a book for pointers in C?I have many of the books but pointers is something which I still think I lack.
...
const struct sockaddr FAR* name,
...