Linked Questions
83 questions linked to/from Why should I use a pointer rather than the object itself?
29
votes
12
answers
16k
views
What is the point of pointers? [duplicate]
What is the point of pointers in C++ when I can just declare variables? When is it appropriate to use them?
-3
votes
2
answers
1k
views
Which is better: storing objects vs storing pointers? [duplicate]
I want to store elements (let's call it E), but I don't know that I should store them as objects or as pointers pointing to the dynamically allocated objects.
(A,B,C,etc. objects store the reference ...
0
votes
4
answers
3k
views
Static and dynamic memory allocation in C++ [duplicate]
Why the following guess is wrong ? (a software engineering company manager told me that it's almost correct but I don't understand why and I can't search for the answer in the Internet..)
int* ptr = ...
-2
votes
1
answer
2k
views
What is the benefit of using a pointer C++ [duplicate]
I Was just confused on the part of using a pointer on C++.. well you might say, "a pointer is obviously a memory adress of another variable and there are certaintly conditions in your program where ...
0
votes
1
answer
922
views
Dynamic Object vs Non dynamic object in C++ [duplicate]
When do you want to use a dynamically allocated object such as, https://leetcode.com/problems/design-twitter/,
Your Twitter object will be instantiated and called as such:
Twitter* obj = new Twitter()...
1
vote
3
answers
489
views
When I want to declare new members for a Struct,some trouble I don't understand [duplicate]
I init a Struct member like this below:
struct MyStruct {
int member_a;
};
int main(){
MyStruct s;//method 1
MyStruct * ps;//method 2
return 0;
}
What's the difference between method 1 and 2 ?...
-4
votes
1
answer
638
views
Printing value of pointer in a vector of pointer c++ [duplicate]
here is my code:
vector<int *> *ptr;
int *tab = new int(20);
ptr->push_back(tab);
cout << *(ptr->at(0)) << endl;
I want to print 20 on the screen, but I got a segmentation ...
1
vote
2
answers
202
views
Why or when to declare an int with a pointer? [duplicate]
Is there any difference between these two other than their duration?
int ptr;
int *ptr = new int;
I understand the concept of pointers but I don't see a much of a use for for delcaring an int with a ...
1
vote
0
answers
252
views
I don't understand the point of pointers to classes [duplicate]
I was reading through C++ tutorial and came across this example code.
// pointer to classes example
#include <iostream>
using namespace std;
class Rectangle {
int width, height;
public:
...
0
votes
0
answers
238
views
Difference between Object object = new Object() and Object object [duplicate]
If I have a class named Object, what's the difference between creating an instance just like that:
#include <stdio.h>
Object var;
main ()
{
var.test();
}
or
#include <stdio.h>
...
-1
votes
1
answer
285
views
C++ data members: Value vs. Pointer [duplicate]
I am beginning development on a substantial personal project and wanted to ask a question regarding data members before doing so.
I am cognizant of the big differences between references and pointers....
0
votes
0
answers
122
views
Benefit of declaring class as pointer? [duplicate]
I know there had been a discussion similar to this in the past but answers appear to be outdated in my opinion. Most say that the differences are the following:
Scope - since on the old questions ask ...
2196
votes
14
answers
767k
views
What is a smart pointer and when should I use one?
What is a smart pointer and when should I use one?
561
votes
5
answers
188k
views
What are copy elision and return value optimization?
What is copy elision? What is (named) return value optimization? What do they imply?
In what situations can they occur? What are limitations?
If you were referenced to this question, you're probably ...
307
votes
8
answers
409k
views
What are forward declarations in C++?
At this link, the following was mentioned:
add.cpp:
int add(int x, int y)
{
return x + y;
}
main.cpp:
#include <iostream>
int add(int x, int y); // forward declaration using function ...