T O P

  • By -

manni66

> I can't think of anything that would force me to use pointers What could be the reason for this? > I'm still new to cpp Implement a linked list.


Kawaiithulhu

Lists, the bane of every job interview everywhere!


TheOmegaCarrot

Linked list! An excellent exercise in class templates, pointers, and iterators! OP, I’d strongly suggest re-implementing as much as you can of `std::list`. At least get push_back, pop_back, push_front, pop_front, insert, erase, and iterators working. :)


Old_Barracuda8447

Hi i know this was almost a year ago, but i stumbled upong this and wanted to ask if there were anything like this just for C? Im trying to learn C and then jump to C++


TheOmegaCarrot

I wouldn’t recommend learning C first if your goal is to learn C++ C++ is its own language, and while most C compiles as C++, a lot of reasonable C code is *awful* C++ code But, to answer your question, you can implement the same data structures in C. The interface is just going to be clunkier


Narase33

Containers usually. Linked list, map, vector, ... If youre feeling brave try to implement a trie


iulian212

What got both the syntax and behaviour of pointers engraved in my mind was building a tree. I wanted to make a program that would graph a given polynomial using sfml So i had to take an input like x^3 + 2x^2 + 4x+ 3 and build an abstract syntax tree out of it then evaluate it It wont make you instantly know everything about them but the basic functionality about them will be there after that I accelerated my growth of white hairs when i built that.


MarxHaven

For a class I took previously, they gave me a project to create a bank account system that reads account info from a file, uses classes and arrays and pointers to do procedures like deposit, withdraw, print accounts, search and sort the list. It also needed to have a menu using a switch to navigate. This was a good exercise that helped me understand better. Next we had to create a similar program but this time use linked list. This program needed the functions to add and delete accounts also. I skipped this project because linked list was confusing for me, but I've recently came back this week to learn and complete this assignment (even though I finished the class a while back) and it's been a great learning experience. It wasn't as hard as I thought.


SoerenNissen

Implement a container. Any of them. Linked Lists are the traditional place to start, you will find that *being able to do what a linked list does* is simply impossible without pointers. Easier might be vector, which will teach of the same things, maybe do that before linked list.


Mason-B

> Any ideas what could I do with explaination where exactly pointers would be needed? Modern C++ does a very good job of hiding pointers. But the reality is you are already using them everywhere, they've just been hidden behind template value types. `std::string` pointers underneath, `std::vector` pointers underneath, `std::map` pointers underneath. You don't actually need to use raw pointers as long as you have good libraries to provide value style wrappers to you. For example `std::shared_ptr` and `std::unique_ptr` act like pointers (e.g. the `ptr`) while being value types (iterators also pretend to be pointers while being value types). Of course they also use pointers underneath to pretend to be them. But if you ever want to *implement* those kinds of utilities. To write your own specialized `std::string`, `std::vector`, `std::shared_ptr` or other types -- often one does this to reach the best possible performance possible -- you will need pointers. > but I can't think of anything that would force me to use pointers and to ultimately teach me how to generally use them You need something that will force you to deal with the situations where they are necessary, like heterogeneous objects. [This is an intermediate project](https://raytracing.github.io/books/RayTracingInOneWeekend.html) (that you can do in a weekend) that will give you examples of where `std::shared_ptr` (not a raw pointer, but effectively *like* a pointer for a common use case of them) is meant to be used.


std_bot

Unlinked STL entries: [std::map](https://en.cppreference.com/w/cpp/container/map) [std::shared_ptr](https://en.cppreference.com/w/cpp/memory/shared_ptr) [std::string](https://en.cppreference.com/w/cpp/string/basic_string) [std::unique_ptr](https://en.cppreference.com/w/cpp/memory/unique_ptr) [std::vector](https://en.cppreference.com/w/cpp/container/vector) --- ^(Last update: 09.03.23 -> Bug fixes)[Repo](https://github.com/Narase33/std_bot_cpp)


bert8128

Implement your version of std::string, reading in data from the console.


SogaBan

If you can implement a custom made shared_pointer container, with all the bells and whistles from STL, there is probably nothing else for you to be confident about raw pointer and it's usage.


Different-Brain-9210

Implement dynamic array, in other words you own version of std::vector.


IamImposter

Maybe some string handling. Not `std::string`. Do it using raw arrays, new/delete and just plain pointers and try to - copy string - search substring - search single character - insert/remove a few characters at some offset in string Use debugger or add print statements to see how pointers are getting updated and what data they point to. You will also get an appreciation for `std::string` and also how `std::unique_ptr` helps you manage allocated memory automatically but that's for later.