0
votes
2answers
245 views

Usage of raw pointers

So from the top-voted answer to this question, it appears that using raw pointers for storage isn't frowned upon so much. However, then what is the point of a std::weak_ptr? I thought that storage was ...
22
votes
4answers
3k views

Why do C++ and Java both use the notion of “reference” but not in the same sense?

In C++ a reference argument to a function allows the function to make the reference refer to something else: int replacement = 23; void changeNumberReference(int& reference) { reference = ...
1
vote
2answers
808 views

Storing a pass-by-reference parameter as a pointer - Bad practice?

I recently came across the following pattern in an API I've been forced to use: class SomeObject { public: // Constructor. SomeObject(bool copy = false); // Set a value. void ...
0
votes
1answer
255 views

Is there a proper way to allow access to private list by reference?

I'm trying to provide a by-reference getter to a list of objects in a class. My setup looks something roughly like this: class c_Container { public: c_Item* Get(int uid); private: c_Item ...
0
votes
1answer
593 views

Converting 'char*' to 'char'. Am I passing this array correctly? [closed]

So my CS professor gave the whole class a simple assignment. "Write a recursive function that will swap the order of a section in an array of chars." I thought to myself, "Easy. I'll finish this up in ...
11
votes
4answers
5k views

C++ why & how are virtual functions slower?

Can anyone explain in detail, how exactly the virtual table works & what pointers are associated when virtual functions are called. If they are actually slower, can you show the time that the ...
1
vote
2answers
702 views

C++ Typecasting VS performance

Let's say we're designing a video game. We have some sprites on the map and we want to call some method of the particular sprite at some particular position. We are using one broadly-known C++ ...
3
votes
2answers
312 views

What happens when using address before it's allocated?

The very simple piece of C++ code below is incorrect, it's easy to see why and tools like Valgrind will tell you. In running several C++ codes containing this kind of error, I noticed that each time, ...
2
votes
3answers
1k views

C++ Pointers: Number of levels of Indirection

In a C++ program that doesn't contain legacy C code, is there a guideline regarding the maximum number of levels of indirection that should be used in the source code? I know that in C (as opposed to ...
2
votes
3answers
2k views

Functions returning pointers

C++ noob here. I have a very basic question about a construct I found in the C++ book I am reading. // class declaration class CStr { char sData[256]; public: char* get(void); }; // ...
5
votes
5answers
1k views

What's so bad about pointers in C++?

To continue the discussion in Why are pointers not recommended when coding with C++ Suppose you have a class that encapsulates objects which need some initialisation to be valid - like a network ...
2
votes
2answers
452 views

The best way to have a pointer to several methods - critique requested

I'm starting with a short introduction of what I know from the C language: a pointer is a type that stores an adress or a NULL the * operator reads the left value of the variable on its right and ...
1
vote
5answers
2k views

What is the point of dynamic allocation in C++?

I really have never understood it at all. I can do it, but I just don't get why I would want to. For instance, I was programming a game yesterday, and I set up an array of pointers to dynamically ...
2
votes
3answers
598 views

introducing pointers to a large software project

I have a fairly large software project written in c++. In there, there is a class foo which represents a structure (by which i don't mean the programmers struct) in which foo-objects can be part of a ...
53
votes
17answers
5k views

What programming problems are best solved by using pointers?

Well, I basically understand how to use pointers, but not how best to use them in order to do better programming. What are good projects or problems to resolve involving the use of pointers so I can ...
4
votes
4answers
2k views

Do I need to understand pointers to use C++?

Well, I love C++, I have been using it for a while: I like all the libraries (Allegro, SDL, QT, Ogre, etc.), but I have a problem: I don't understand pointers. Do I really need them ? I just program ...
3
votes
5answers
1k views

function pointers are so complex to me

I found this code sample in this answer by Armen Tsirunyan. class MyClass { public: typedef void (*funcPtr)(int, int); MyClass(funcPtr whatToCall) { callme = whatToCall; } ...
4
votes
2answers
811 views

Smart Pointers inside class vs Normal Pointers with Destructor

Regarding pointers which are members of classes. Should they be of a smart pointer type or is it enough to simply deal with them in the destructor of the class they are contained in?
22
votes
10answers
6k views

Why are pointers not recommended when coding with C++

I read from somewhere that when using C++ it is recommended not to use pointers. Why is pointers such a bad idea when you are using C++. For C programmers that are used to using pointers, what is the ...
11
votes
5answers
1k views

If you favor “T *var”, do you ever write “T*”? [duplicate]

Possible Duplicate: int* i; or int *i; or int * i; Thinking about where we place our asterisks; how do those that prefer to keep the "pointerness" away from the type and with the identifier ...