I believed in C++

I believed in C++...

How the hell do I make an object own a property with its own type?

Other urls found in this thread:

cslibrary.stanford.edu/102/PointersAndMemory.pdf
youtube.com/watch?v=mnXkiAKbUPg
twitter.com/SFWRedditImages

pointers

pointers with structs?

Recursive struct definitions are not exclusive to C++.

Haven't you ever written a linked list?

class Node{
private:
Node* next_node;
...
}

Pointer or reference to it.

But if it's a reference, then the constructor is required to bind the reference using the special constructor initializer syntax. Example:
class c
{
public:
c &property;
c() : property(value) { ... }
};
// value is the c object that property is bound to


Pointer doesn't have any restrictions like that.

Just don't.

As in not through a pointer or reference?

Well, you could make templates that recursively expand..

>Destructor
Remember the rule of three.

You also are probably looking for a pointer.

Alright. That's it. I'm fucking asking. I've used all the scrub languages: BASIC, bash, JavaScript, PHP, and I have never once in my life coded in C++. You guys keep throwing that fucking word around and it just always seem to mean something different. It's like you made it up to fuck with people or something. So, I'm asking: WHAT THE FUCK IS A POINTER!?

A variable that stores the memory location of something.

OP, how can you make an object with one of its properties having its own definition? Won't that cause an endless recursion when you instantiate it? The property will be an instance of the object, which will have an instance of the object as one of its properties, and so on.

Then how can you use a pointer for an object's definition? Won't that make the object's property just... an object definition, rather than an instance of the object?

Please go reread the first chapter of your C++ textbook and come back

already explained what's a pointer.
You create it like this: type* variable;. At this point it's value is 0, and if you try to access it(dereference), your application will crash.
To assign new value to it you use new operator like this: inception* dream = new inception(args) or int* arr = new int[size]. First is for objects, second one is for dynamically allocated arrays.
You also have to delete it after use. Like this delete dream; or delete[] arr;. Just like as above, first is for objects and second is for arrays.
Solution to your problem would be:
inception* dream;
inception* dreamTunnel;

//in constructor
dream = new inception;
dreamTunnel = new inception;

//in destructor
delete dream;
delete dreamTunnel;

Read a book nigger

I think most of the people here are assuming OP really wants a linked structure.

A class or struct in C/C++ can contain pointers to an object of its own class, or an actual full object of another class.

Strictly speaking, you can't do something like having an object of a class contain another object of the same class.

I think you can do recursive template instances though, as long as you can have some way of terminating it. I could be wrong on that, though..

computers are hard

>You create it like this: type* variable;. At this point it's value is 0, and if you try to access it(dereference), your application will crash.

Small nitpick here, but if you just do : type* variable; then variable would be uninitialised - just whatever was in that memory before (a wild pointer). You're correct in saying you should use the new operator before dereferencing it, but It's better to initialize it to zero before that.

type *variable = nullptr;

With a pointer or reference type. Look at your inception type that you gave as an example. Ask yourself: how many bytes is this object? You would likely surmise that since there are two inception objects in it, that the size is twice the size of an inception object. So this creates the identity sizeof(inception) == 2 * sizeof(inception).

Obviously, this creates an issue. But a data pointer is going to be the same size regardless of what it points to, so if inception had two inception* members, you could easily argue that sizeof(inception) == 2 * sizeof(inception*) == 2 * sizeof(void*).

How the fuck are you trying to code in c/c++ without knowing what pointers are? At least read a tutorial or something before shit posting on Sup Forums Jesus fucking Christ

>WHAT THE FUCK IS A POINTER!?
Read this:

cslibrary.stanford.edu/102/PointersAndMemory.pdf

And for the record, you should be covering the basics of C++ programming, including pointer and reference types, BEFORE you get into object oriented programming.

I literally said I never coded in C++ you stupid fucking baboon. Do you just understand the opposite of what you're told when it gives you a reason to get mad at someone?

>So, I'm asking: WHAT THE FUCK IS A POINTER!?
this is what programmers are in 2017, everyone. not knowing even _conceptually_ what a pointer is, and unable to use google.
I bet this dude is going to write software for hospitals and life sustaining machines or something in ten years.

I'm not a programmer. The meager coding skills I have, I learned them on my own.

>I'm not a programmer.
exactly like most programmers today

Uh huh. That's cool. I never said I was a programmer and your cynical remark is a misfire. You should feel embarrassed about the autistic fit you just had over presumptions you made on your own.

Hey user, I learned C++ on my own too, and I still learned what pointers were pretty quickly. Classes and objects are supposed to be something you learn after learning the basic components of the language. So you should already understand things like pointers, references, array types, etc...

I didn't learn C++, ever. I already said that TWICE. You guys are absolute fucking morons.

>code in piss easy dumb languages
>jump straight into a lower level, more complicate language
>shit doesn't work
>does not read books
>does not even read/watch basic fucking tutorials on the language
>what the fuck is a pointer
>get mad

Fuck off you triple nigger, try educating yourself before monkey raging

stop getting buttblasted and accept that you are missing fundamental and basic programming knowledge required to achieve what you are trying to do

go read about pointers and memory management instead of asking here

Are we assuming that the guy that asked what a pointer was is the same guy that asked the original question?

I figured it was a random additional negro.

... I'm not OP.

You guys are exasperatingly retarded. Why the fuck did you think I was OP? Because it was the scenario that fueled the most vitriol?

Yet you are clearly teaching it to yourself, as evidence by the fact that you are trying to ask questions about C++ classes. What you should take out of what I am saying is this: you are learning the language features in the wrong order. Learn the basics first, THEN tackle advanced concepts like OOP.

Use pointers. Anything else is retarded.

Consider if it allowed you to make a class containing an instance of itself. The inner instance would contain another inner instance, and so forth. All the RAM in the universe would not be large enough to contain a single complete instance of your class.

Ruby fuck off. You are the most self-important piece of shit on this board. I took a look at this thread out of curiosity and decided I was done not understanding anything when people talk about pointers. Stop twisting everything into a pretend reality where you're in a position to lecture people and enlighten them with your wisdom.

>Stop twisting everything into a pretend reality where you're in a position to lecture people and enlighten them with your wisdom.

I'm about a month and a half away from graduating with a master's degree, and I've already been accepted into a PhD program. I think I'm at least qualified to lecture people on the order of features they should be studying when trying to learn C++. It should be quite obvious that pointers are ideally learned before OOP concepts, given that the "this" pointer cannot be understood without first understanding what a pointer is in the first place.

lol

>Ruby frantically trying to rationalize his bullshit

You're just precious. I wonder how many decades of being insufferable and getting rejected by every one of your coworkers it will take before this "It's everyone else who's wrong" narrative runs out of fuel.

Well then, user, since you've clearly taken an opposition to my statements, what have I said that is in some way incorrect or bad advice?

I already explained what was wrong with your posts. It went way over your head because people like you ignore inconvenient information.

What's wrong is that you're not giving advice to help anonymous. You're giving advice to fuel your inflated sense of superiority.

>Everyone knows C++ is a pretty fucking complex language
>Gotta go code on C++!
>Fuck! How do I do stuff?
>Gotta go ask user!
"The stuff is done this way"
>"This way"? Are you trolling me, user? What kind of a magic spell is this?
"Read a book"
>Oh my god, what an entitled piece of shit!
>I'm a strong and independent non-binary trans! My behavior of asking for an advice and then being an obnoxious dick about it is objectively correct!

De/g/enerate mentality: the thread.

OP and the person who asked about pointers is not the same person, but whatever makes you feel good about yourself.

Mind pointing out which posts of yours are counterarguments to me? Because I don't see any backlinks on any of my posts to actual arguments.

I gave user a link to a good resource from Stanford University on learning about pointers. I then told him to stop learning about features out of order, which should arguably be sound advice. If you do not understand the basics of a language, you cannot be expected to understand the more advanced features. Pointers are part of the basics of C++. They are a primitive data type, just like integers and floating point numbers.

>I gave user a link to a good resource from Stanford University on learning about pointers. I then told him to stop learning about features out of order, which should arguably be sound advice. If you do not understand the basics of a language, you cannot be expected to understand the more advanced features. Pointers are part of the basics of C++. They are a primitive data type, just like integers and floating point numbers.
cool story bro

>I didn't learn C++, ever. I already said that TWICE. You guys are absolute fucking morons.
OH MY GOD. You are actually making me break it down for you. You're so fucking exhausting.

>I didn't learn C++, ever. I already said that TWICE. You guys are absolute fucking morons.

I AM NOT LEARNING C++. DO YOU UNDERSTAND THIS NOTION AND ITS IMPLICATIONS? I AM NOT OP. I'M NOT CODING ANYTHING IN C++. NONE OF YOUR LECTURING IS RELEVANT TO MY SITUATION.

Obv. I meant to quote you in the first greentext in , but whatever, you get the idea.

Probably should have stated in your original post that you weren't OP if you didn't want people to mistake you for him. Alternatively, not posting in someone else's thread with your own new problem.

No I don't have to clarify shit just to make sure you avoid making wide leaps and baseless presumptions. It's your responsibility not to systematically jump to the conclusions that give you an opportunity to get on your pedestal and talk down to people.

Besides, as demonstrated in this thread, you ignore details that contradict your understanding of things, so it's not even worth trying to deal with you. You'll just believe whatever makes it fit for you to lecture others because that's the only shit you do in this board: Lecture people. If you didn't have opportunities to lecture people, your ego would wither and die.

Space ship life support systems?

Given that I am not the only poster to make this assumption, yes, you should. Especially considering that you made your post as a response to a post responding to OP. You then say things like:

>You guys keep throwing that fucking word around and it just always seem to mean something different
Right after everyone tells OP to use a pointer. It would seem from context that you would be OP responding to being told by everyone to use one, and not understanding the instructions.

Welcome to anonymous imageboards. This shit happens all the fucking time. It helps to clarify who the fuck you are in reference to the discussion at hand, if you wish to not be misunderstood. And yes, when you are seeking help, the onus IS on you to avoid misunderstandings. The onus is also on you to Google before asking stupid questions, or you will be treated like the annoying little prick that you are.

...

>WHAT THE FUCK IS A POINTER!?
youtube.com/watch?v=mnXkiAKbUPg
>8 years old
Jesus.

...

wait that was supposed to quote

ruby is so fucking insufferable
added to filter

>property
That is not a C++ term. Seriously, what the fuck is a property?

He probably meant member.

class Inception {
void *attribute;
}

attribute = new Inception();

Forward-declare inception, like this. I think it might work.

class inception;

class inception {
inception* previous;
inception* next;
}

Why is that even a question? Go back programming Python.

LE CURRENT YEAR DEVELOPER

heh, this whole thread...
good job, OP

class inception {
private:
std::unique_ptr dream;
};

One of the first things anyone should implement, regardless of language, is a linked list and a binary tree.
It forces you to learn about pointers, recursion and memory.
Something like an AVL tree or a snake game is good exercises and teachers often use them in schools when people are new to programming.
If the application fails valgrind, they fail the class.

Can you guys c++ experts help me with my thread:
I'm sure it's super simple but I've never used that "initializer_list", thanks!

>Doesn't know what pointers are
>Calls other people stupid baboons

the irony is palpable