What are some low level languages that rape your perception of how things work in unexpected ways?

What are some low level languages that rape your perception of how things work in unexpected ways?

[spoiler]Please help me fix this.[/spoiler]

Attached: Untitled.png (706x287, 15K)

Other urls found in this thread:

urbandictionary.com/define.php?term=rape whistle
isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-regular
isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-copy-virtual
twitter.com/NSFWRedditGif

>What are some low level languages that rape your perception of how things work in unexpected ways?

They don't "rape" you with "unexpected" things. That is why they are low level.

First day on a static type system, eh?

does Post extend Text?
try new Text *newPost1->fieldWithText or something

haven't written c++ since '11

Text is-a Post
>new Text *newPost1->fieldWithText
Nani the fuck?

weren't you the genius that decided to explicitly disable the copy constructor?

there's your problem

alternatively, show your entire code.

i c-c-changed a few t-t-things

Attached: Untitled.png (1023x629, 39K)

I mean why the fuck does it not work? newPost1 points to a fucking Text object.

but ofc. sorry.

if text isa post, post ainta text

post needs to extend text for the copy constructor to work, because a Post object can be missin attributes that a Text may require.

that's probably the real problem.

So I should make a virtual constructor?

>using char* in C++
just why? if you need C-like nul-terminated strings use cstring

maybe the problem is that constructor if for reference while you are trying to pass a pointer?

now the real real real problem

has to do with try *((Text*) newPost1)

make a post constructor, or recast the pointer to text

why the fuck would you store it as Post* anyways?

The tool tip in OP pic says I'm trying to pass a Text to a Pointer.
Why the hell is it trying to call Pointer constructor when I'm allocating a Text?
Is this not upcasting? I thought upcasting is evil and UB.

>Is this not upcasting?
you started it

so you do have a copy constructor

try new Text((Text) newPost1)

actually don't.

read more about types, inheritance etc. keep your types more sane, and don't recast a new object pointer.

Cha-ching, this is it bois. Thanks.
I am making an array of Posts and I need this to be polymorphic. Can I somehow make somehting like
virtual Post* copy() const override
{
return new Text(*this);
}

You can insert a Text* directly into an array of Post*.

Huh? I was thinking of Post* postsArr[100];
postsArr[0] = new Text(....);
postsArr[1] = new Link(....);
postsArr[2] = postsArr[0]->clone();

Does VHDL count? Sometimes things just don't work because of timing or metastability.

Do you actually need to copy it here? postsArr[2] = postsArr[0]; will probably work fine until you start thinking about memory management. If you do, then yes, you need a virtual method defined for each subclass to call the correct constructor.

WHAT
WHY DOES THAT EVEN WORK

Ive learned that there are exceptions in low level programming which blows my mind since it seems like such a high level concept

Pointers merely point; they are not the object itself.

Attached: this is not a pipe.jpg (1442x1005, 1002K)

Doesn't that leak memory?

Not if you destruct them responsibly

static cast newPost1 to Text* then dereference it.

Red or blue, Jow Forums?

Attached: Untitled.png (415x188, 6K)

What the heck do you mean?

The argument for post1 is a string
The argument for post2 is a Post

what?you mean where the text object is in the ram?its in the heap segment of your process.

>low level languages
>C++
ayyy lmao

>help me fix this
There's no constructor that takes an argument of type Post.
What is there to say? You're using the api wrong. In a language that just let's you do this (think python) you'd just get a runtime error with internal details of the constructor failing to operate on Post. Much more cryptic. Be happy that you get such clear errors.
Read the docs.
>does x extend y
Irrelevant to this issue. All that matters if there's an appropriate constructor.

The new to delete ratio here is already infinite, so it doesn't really change anything. Better to learn idiomatic C++ memory management any way.

>10000 hours in mspaint
Red. Now do multiple inheritance.

new returns a fucking pointer

Yes it should, that's how inheritance works.

Yeah I was thinking this
My experience is almost entirely with C but isn't the problem just that the 2nd constructor argument isn't a string but a Post, which isn't compatible
So you'd cast the argument to pointer to character (assuming that Text has the string as the 1st thing in memory)

This isn't "low level that rapes your perception", such a mistake would be done in higher level languages too

Based on
It's Red more than blue. But to be accurate the bar 'Text' contains no post.
See pic. It's a video explaining dynamic cast but this is a good visual representation. Cat inherits from animal. So cat data is appended to animal data and the vptr (if it exists).
This is the exact same for your situation. Text is cat (derived) in this example and post is animal (base).

But this is still irrelevant to the current issue. A constructor operates on what you pass it. It doesn't automatically copy paste whatever you pass in where you want it.

Attached: Screenshot_20180525-163309~01.png (1920x1080, 735K)

>go to university to learn programming
>oh boy i cant wait, python and ruby are so "in" right now
>first class
>lecturer brings a bag with literal whistles and hands them out
>YOU KNOW WHAT THESE MEAN CHILDREN
>writes c++ 101 on the board
I'm not shitting yu, I still keep mine.

>>lecturer brings a bag with literal whistles and hands them out
>>YOU KNOW WHAT THESE MEAN CHILDREN
I don't. Maybe it's a 'murican thing. What do those mean? Rape warnings, something of the sort?

I don't get it.

urbandictionary.com/define.php?term=rape whistle

It's been a thing in my country since the migrant crisis.

>university
>children
Spotted the problem with sheltered US (((academia)))

Poor immigrant teenage girls being raped by cis het white men ;^(

>US (((academia)))
Bulgaria.
>cis het white men ;^(
Gypsies and sand niggers.

>buggeria
Has the (((sheltering))) spread there too? I thought you and the rest of the East were one of the last bastions of almost-decency in Europe

>almost-decency
Typical foreigner. I'd rather live in fucking compton but carry a glock on my hip than live in this hellhole. Gypsies walk in groups and fuck with people. If you defend yourself, you either go to jail, or a dozen guys show up with pickaxes on your door.
The only decent thing are naturally beautiful women, which is completely ruined by the 'scenic thot' attitude that's really hip right now.

If the class owns the string, use std::string. If you don't, store a std::string_view or simply a const char *.
No need for custom copy semantics this way.

What's wrong with custom copy semantics?

They are mostly useful for creating custom containers, or to disable certain behaviors (deleting them, like OP did before).
It is better to have regular types for the kind of application-level code that OP showed.
See also:
isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-regular

Another question: do I need to make a virtual clone method, following the rule of three, given inherited class.

Why are you using pointers and memory management? That should be nested inside your classes ctor. You obviously dont know what you're doing and should not be using C++

Can you point out the exact lines of code that are wrong?
>should not be using C++
>you're not allowed to learn, never ever!

I guess you are referring to this:
isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-copy-virtual

Sure, you'd need that if you're creating derived objects through pointers to base (by cloning them).

>you'd need that
I don't know if I'd need that. Is it a bad idea to just slap functionality in case I need it later or because the user might expect it to be there?

Well, it's better to have the least amount of code that fulfills your requirements. If I were you I'd stick to regular types and smart pointers for memory management. It's easier to reason about and show that it does what you expect.

#include

struct Post {
virtual std::unique_ptr clone() = 0;
virtual ~Post() = default;
};

struct Text : Post {
Text(const std::string &s) : s(s) {}
std::unique_ptr clone() override {
return std::unique_ptr(new Text{*this});
}
std::string s;
};

int main()
{
auto t1 = std::unique_ptr(new Text{"foobar"});
auto t2 = t1->clone();
}

So I should tick smart/unique pointers and move semantics on my to-learn list.
Thanks for the help, you and everyone.
Final question:
Now every user needs a Post container. Can I get away with making my own or can I somehow use vector.h?

Post * blah = new Text(*statc_cast(newPost1));

Do you just need an array of posts for the user? I would use a vector in that case.