[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

c++

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 165
Thread images: 14

File: cpp_logo.png (23KB, 360x405px) Image search: [Google]
cpp_logo.png
23KB, 360x405px
this language is weird.
>>
>>60830378
> C++
its a bloated shitty language without the performance of C, the portability of Java, or the convenience of Python. stupid language needs to die already
>>
>>60830378
basically the opposite of what >>60830440 said is true
>>
>>60830378
C++ is a fucking garbage, it has 2 fucking standard libraries, 2 different implementations of modules and 3 fucking ways to define an integer:

int x = 1;
int x (1);
int x {1};

LMAO what a fucking piece of shit. C++ is the epitome of garbage. I even think it's worse than Java.
>>
C# is superior!
>>
>>60830516
/thread
>>
>>60830561
You do realize you are in the wrong thread, right? Take your babby virtual machine language and get out
>>
>>60830616
>you
>>
>>60830557
>3 ways to define an integer
> int x =1
It's declaring and then assigning a value

>int x(1)
It is constructing the declaration from a value

>int x{1}
It is constructing the declaration from an initializer list

Only retards wouldn't understand this. I bet you think std::move is pointless and pointers are superior to (const)references in all cases.
>>
>>60830561
top lel
>>
If you care about where your data is in memory, use C++. Otherwise, you could probably be more productive with something like C#.
>>
>>60830694
C# is slower than java
>>
>>60830667
>3 ways to define an integer
C++ cucks are defending this with their best strawman
>>
>>60830701

Not in a meaningful measure for any application where you would be using C#/Java in the first place.
>>
>>60830781
What do you mean?
>>
>>60830808
He means performance is not important. Typical C#/Java cuck
>>
>>60830440
>bloated
Yep.

>without the performance of C
It is just as fast as C if you know what you're doing, it gets slower if you abuse it's features but A: that's inevitable if you want a language that's usable for large projects and B: mostly avoidable.

>the portability of Java
Portability's okay actually. Particularly with boost. I have a massive C++ project and the OS specific code constrained with typedefs is probably 100 lines out of 120,000 (DLL loading and process launching mainly iirc).

>or the convenience of Python
Totally depends on the platform. On Linux it's comparable, there's one additional build script which is a little bit of stuffing about, but other than that. On Windows I totally agree, it's a nightmare you only want to pull out for serious business.
>>
>>60830822
>performance is not important.
In that case just use pyshit.
>>
>>60830808

If I'm doing performance critical programming, it's going to be in something like ASM/C/C++.

If I'm using C#/Java, it's generally for an application where an additional few ms running don't really matter.
>>
>>60830828
I meant the preprocessor, not typedefs, oops.
>>
>>60830845
>>60830833
>>
>>60830440
Bloated? Yes. ill-performant, inconvenient, lacking portability? No.

Are you mad because you had to retake a class? Or do you meme because you hear it's the hip new thing to do?
>>
>>60830828
> Totally depends on the platform. On Linux it's comparable, there's one additional build script which is a little bit of stuffing about, but other than that. On Windows I totally agree, it's a nightmare you only want to pull out for serious business.

It will be easier if I start learn to code c++ in linux based os?
>>
>>60830714
The fact that you don't understand this makes me question your ability to navigate through life anon
>>
>>60830866

I prefer C style syntax. It's easier for me to move between C/C++/C# for different projects than something totally different like python.
>>
>>60830893
>Still trting to control the damage
LOL I wonder why C++ is the longest running historical failure
>>
>>60830378
you just have to git gud at pointers
>>
>>60830891
Not that poster - but certainly. Although now you can use comfy bash in windows so it's a little better. Also some good windows IDEs these days like CLion.
>>
>>60830891
Absolutely. On Linux you can mostly just use your package manager to get any dependencies you need and their files will be in the path by default, so you just add the names of the dependencies you want to your build script and off you go.

On Windows you have to download the packages manually, sometimes compile them and then add paths to your Visual Studio project (through a set of menus mind you, not by editing a script, I find it's much slower).

You can use various tools to make Windows behave like Linux for this purpose like Cygwin or (presumably, haven't used it) the new Linux subsystem, but at that point you might as well use Linux.

Additionally, Linux doesn't try to push you into using Visual Studio and stupid "project files" which aren't really intended to be edited by hand and which will cripple your portability. You learn CMake or something comparable straight away and it removes a lot of the mystery and improves portability.
>>
>>60830931
That's not a hard thing to attain. If you are good with pointers you don't need C++ over C anyway
>>
>>60830924
I'm not saying it's great. It's old as fuck and basically 3 languages in 1 at this point. My problem is you're too stupid to recognize what's actually wrong with it, rather than just parroting the trifles you've heard from others
>>
File: Windows shilling book.jpg (50KB, 591x722px) Image search: [Google]
Windows shilling book.jpg
50KB, 591x722px
>>60830964
>>60830946
Post yfw Bjarne is a literal windows shill
>>
>>60830946
>>60830964
Thanks
>>
>>60830931
Half the benefit of using C++ is exactly that you don't have to spend forever managing pointers.
>>
>>60830867
I love that this was overlooked by all the retards in this thread.
Well met.
>>
I don't get why people think there is bloat. The whole point of C++ is to pay for what you use.

int main()
{
using log_n = std::variant<const char*, int>;
std::array<log_n, 4> arr = { 0, "op ", "is a ", "fag\n" };

for (auto e: arr) {
std::visit(overloaded {
[](const char* s) { write(1, s, strlen(s)); },
[](int i) { write(1, "hello ", 6); }
}, e);
}
return 0;
}

text data bss dec hex filename
659 0 0 659 293 a.out


I can use std::array, std::variant and lambda functions without touching the heap at all, building a freestanding binary.
>>
What's the best book/site/resource to learn C++?
>>
>>60831274

The Best Way to Learn Every Language
1. Come up with a project
2. Build until you find something you don't know how to do
3. Google how to do that thing
4. Repeat 2 and 3 until you're done.
>>
>>60831274
cppreference.com and cplusplus.com are invaluable resources, I use them for all standard library stuff and for looking at a couple of the more obtuse features. cplusplus does have a tutorial but I don't know how good it is.

boost.org/doc/libs/1_64_0/ is a must for the boost documentation which is very high quality and you're going to want to use Boost, it's basically the third standard library for C++ that adds networking and filesystem functionality (as well as tons of other useful stuff like common string algorithms).
>>
>>60831274

It kind of depends on what languages you already know. Try looking for "C++ for <language> developers" guides.
>>
>>60831312
This is a good idea, but for C++ it won't take you all the way. C++ is a very very feature heavy language and you will reach a point where you know how to do everything moderately well and you'll never find the more obtuse stuff.

After you've leveled out doing this, look at some code from some libraries to see the features you're missing, go through the list of keywords, look at lists of stuff added in the recent versions, that sort of thing.
>>
>>60831312
seriously who needs comp sci
>>
>>60830440
>>60830378
>>60830714
>>60830965

>FOREVER BRAINLETS
>>
Will be replaced by languages like Swift, Rust etc..

Yes, established companies will stick to it until the bitter end, but new companies won't/can't put up with that garbage. And no, C++ won't have the same fate as Cobol has. Cobol is only still around because all the banks used it, and banks can't go bankrupt. Your average game developer can and will.
>>
No game dev company that cares about performance uses C++ or any of its features. Look at any C++ con talk and you will see. EA Games even made their own standard libs for Cpp.

Now stop shilling this Java 2.0 shit and go #include "QString.h"
>>
>using a proprietary language owned my microshills
>>
>>60833267
C++ is for brainlets that don't understand pointers. That's why C++ monkeys need smart pointers
>>
>>60830557
what the actual fuck. is this real?
>>
>>60830557
>worse than Java.

impossible
>>
>>60834421
>FOREVER BRAINLET
>>
>>60831202
what does this do?
>>
>>60834565
it prints hello world
>>
>>60831202
Why don't you just write that shit in Lisp instead?
>>
>>60830557
Stop reposting this meme

>2 standard libraries
boost isn't a standard library, although it is pretty nice

>2 ways of implementing modules
???
C++ doesn't have modules

>3 fucking ways of defining an integer
Are you retarded?

This declares an integer.
int i;


That's the only way.

What you're talking about is initialisation.

int x = 1; // this declares an integer x and assigns it
int x(1); // this is the old-style (pre C++17) way of declaring an integer and initialising it to 1 (different than assignment)
int x{1}; // this is the new-style (C++17 and newer) way of initialising, and it is consistent with how you initialise arrays and structs

I don't know what kind of brainlet you'd have to be to not know that there's only one stdlib, there's no such thing as modules in C++ and assignment/initialisation isn't "defining an integer"
>>
>>60836614
Sure, if you have no restrictions on rom/ram use, it is better to use Lisp instead. I was just showing what you can do in C++ with just 659 bytes.
>>
/g/ I don't understand polymorphism in c++

If i have a std::vector<animal>,
why can't i do this

class dog : public animal {\*...*\};
std::vector<animal> animals;
animals.push_back(Dog d());


What's the correct way do handling this?
>>
>>60834565
It takes a static array of a type-safe union of const char* and ints. Then it iterates over those and selects the lambda that matches the correct element type.
>>
>>60836717
You're not writing proper syntax.

#include <vector>

class animal
{
};

class dog : public animal
{
};

int main()
{
std::vector<animal> animals;
animals.push_back(dog());
}
>>
>>60830667
>Hey look here are the names of what it is doing, they all do the same thing though, store a value and refer to it as x.
>>
>>60836717

You need to use a std:vector<animal*> or some other pointer type. Polymorphism only works through pointers and references, and trying to do polymorphism on values either doesn't work or does the wrong thing.
>>
>>60836742
The difference becomes apparent when you work with user types, though. Assignment, copy construct and initialisation list are clearly very different.
>>
>>60836738
I doubt your code will work. It it was a vector of pointers, it would. Assigning a dog to an actual object of type animal is impossible.
>>
>>60836738
Thanks dumbas, it's an example do you really think in writing oldMcDonaldsFarm.exe you fucking moron?

>>60836747
Thanks!
>>
>>60836742
>Three completly different things that do the same for one specific type.

You clearly understood CPP.
>>
>>60836717
It won't work since dog can have a different size than animal. One way to deal with this is to use pointers.

#include <memory>
#include <vector>

struct Base {
int bval;
};

struct Derived : Base {
int dval;
};

int main(void) {
std::vector<std::unique_ptr<Base>> vec;
vec.emplace_back(std::make_unique<Derived>());
return 0;
}
>>
>>60836763
>>60836747
You are a mongoloid
>>
>>60836787
Now give animal and dog one private member each (e.g. age and a string race) and put 3 dogs in there.
>>
>>60836797
>>
>>60836787
I'm the original polymorphism guy.

What if you had member data for your classes, and dog had an extra property over animal, like breed or something?

Still good?
>>
>>60836822
See >>60836819
>>
>>60836822
>>60836819
oh im too slow
>>
>>60836787

Anon fails to understand object slicing and the dangers of copy constructing a base type.
>>
File: HqQqusa.png (125KB, 1637x922px) Image search: [Google]
HqQqusa.png
125KB, 1637x922px
>>60836787
It's broken, anon. Your thing doesn't work. It won't even compile if you add any field to dog class.
>>
>>60836819
You are creating those dog objects but ones that are put inside vectors are not them. In your vector are just generic animal objects.
>>
>>60836856
>>60836849
>>60836839
Yeah, you're right.
>>
>>60834534
C++ is the epitome of trash, it's worse than Java
>>
>>60834544
>>60833267
You have to be 18 to be posting here. Get out.
>>
>>60830557
/thread
>>
>>60830378
C++ is the longest running historical failure as a language. It'll never surpass C.

Even Rust is now faster than C++, it'll probably kill C++ in the coming decades too. What a miserable fate.

Enjoy writing header files in the meantime like the '70s.
>>
File: CWdQa7OUkAAQ1-A.jpg (47KB, 600x400px) Image search: [Google]
CWdQa7OUkAAQ1-A.jpg
47KB, 600x400px
>>60836956
>>
File: 1488577937023.png (81KB, 512x288px) Image search: [Google]
1488577937023.png
81KB, 512x288px
>>60836997
keep crying, mouth drooling dipshit
>>
>>60837184

>I can't read a box plot
The median execution time for C++ is below Rust.
>>
>>60837184
>Java is faster than C# these days
kek
>>
>>60837385

The JVM works wonders for that shitlang.
>>
>>60830667
>> int x =1
>It's declaring and then assigning a value
Actually no it isn't, it acts the same as int x(1); when the compiler sees you both declare and assign on the same line
If you want it to declare and then assign, you need to split it in two lines
Try it yourself
>>
>>60837184
I wonder what is the point of such charts. I mean, you are actually comparing LLVM and GCC vs stuff like the JVM and the CLR + whatever runtime the language uses.
If anything, it shows that we should be using Lisp /Scala/Haskell for non-realtime applications.
>>
>>60837511
All JVM and CLR languages do not perform the same, idiot. Do some more research.
>>
>>60837523
I see that from the chart. My point still stands: if you don't have real-time constraints, use the highest abstraction language that you like, as the performance difference will be less than 10x.
If you do have those constraints, you won't be using a VM-based language anyway.
>>
>>60830378
Yea. But in all honesty, it's more practical than C.
(Just dumping some thoughts)

I get that C is small, functional and pure. But...

You get a working, non-third party standard library. No complexity for complexity's sake.
You get the "auto", which means you don't need to use the abominable void*.
Data can be abstracted more easily.
Function overloading ma nigga, also operator overloading.
Meta programming!
I also find that when using C I have to write like 4 times more code for the same thing in C++.
I find it easier to read C++, which is a HUGE plus as it makes it easier to understand and debug. But it might just be that I'm not as used to reading C.

C++ is low-level enough to be performant, yet high level enough to be readable. But I guess C is still useful for a lot of people doing low-level applications etc.
>>
File: 1474118959321.png (40KB, 1620x774px) Image search: [Google]
1474118959321.png
40KB, 1620x774px
>>60838273
But, yea, I do see why a lot of people look at C++ like pic related.
>>
>>60837511
>>60837184
Not to mention that he's using boxplots on an exponential scale, which obviously skews the quartiles....
>>
How is D compared to C and C++? I don't like the clusterfuck of C++, but C lacks features (like any kind of polymorphism).
>>
>not programming directly in machine language
>>
>>60838399
D is everything I could ever hope of C++
-Modules
-Robust templates
-No header files
-No C prepocessor
-Cleaner, intuitive syntax
-Optional non-gc programming and the list goes on
>>
>>60838425
Oh it has patter-matching (in form of pred switch), maps, folds, zips, each, foreach (with index), auto, etc.

You can do functional programming in D as comfortably as OOP and linear imperative programming
>>
>>60838399

Don't think of D as an alternative to C++. Think of it as an alternative to Java and C#. It doesn't work otherwise.
>>
>>60838425
h-files are a blessing and a curse.
You get to forward declare things in the h-files and only include the files you need in the cpp-files, which reduces compile time.
But then again, it kind of sucks having to separate the code up like that.
>>
>>60838287
It is mostly people who don't understand programming who do that.
I use C++ for what I call desktop applications.
I use it in an embedded context, but I still rely on the OS to be there and to handle a lot of things for me.
There is times where the language is a pain, but I find that it is when a library is written in C, but is supported in C++.
Stuff where they support function overloading, but only through a static void pointer function and where they use C style strings etc, so I view it as the flaws in C that come through as the problem.
>>
>>60838458
I think Rust as an alternative to C++. D is much more comfortable than any of C, Rust, C++, Java, Microsoft Java
>>
>>60838464

When it comes to compile times, module systems are easily faster than header files.
>>
>>60838425

>-Optional non-gc programming and the list goes on
And all you have to give up is the standard library and whatever other 2 or 3 libraries exist for D.
>>
D has conditional compilation. This is one of the features that I frequently miss when I'm programming in C++. If C++ would add it, then C++ would improve by leaps and bounds when it comes to stuff like templates.

D has compile-time reflection.

Variables are thread-local by default but can be shared if you want them to be. This makes dealing with threads far cleaner than in C++. You're in complete control. You can use immutable and message passing to communicate between threads, or you can make variables shared and do it the C++ way with mutexes and condition variables. Even that is improved over C++ with the introduction of synchronized (similar to C# and Java). So, D's threading situation is far better than C++'s.

D's templates are far more powerful than C++'s templates, allowing you to do far more, far more easily. And with the addition of template constraints, the error messages are way better than they are in C++. D makes templates very powerful and usable. It's no coincidence that the author of Modern C++ Design is one of D's main collaborators. I find C++ templates to be seriously lacking in comparison to D templates, and it can be very frustrating at times when programming in C++.

D has built-in contract programming.

D has a built-in unit test framework.

D has built-in support for unicode with string (UTF-8), wstring (UTF-16), and dstring (UTF-32). It makes it easy to deal with unicode. And if you want to just use string and generally not worry about unicode, you can - though some understanding of the basics of unicode does help with some of the standard library functions.
>>
>it's another episode of "webdevs and two-bit programmers shit on a language they don't understand"

All the criticism C++ has received over the years has already been answered many times over.
It's not bloated, features are added by a complicating process that begins with requests from heavyweights who use C++, like the MIC and large corporations, then the committee analyses the request and after long talks it's implemented. Just because you don't need a feature doesn't mean others don't make use of it.
It can be just as fast as C which isn't surprising if you knew anything about C++, which just goes to show the kind of morons that pick on the language.
Seriously, the only people who should have the right to comment should be those who work with low level languages, in other words C/C++ users ( meme languages are excluded ). The rest of the retards should stick to webdeving and stfu.
>>
>>60838526
D's operator overloading is much nicer than C++'s, allowing you to use one function to overload multiple operators at the same time. A prime example of this is when you need to overload the basic arithmetic operators and their implementations are identical save for the operator. String mixins make it a breeze, allowing you to have one, simple function definition for them all.

D's arrays are vastly better than C++'s arrays. Not only are they a proper type with a length, but they can be appended to and resized. Concatenating them is easy. And best of all, they have slicing. And that's a huge boon for efficient array processing. Strings are arrays of characters in D, and it's not a problem (in fact it's great!), because D's arrays are so powerful.
>>
>>60838521
If I am not using GC I am not using stdlib either, it makes the perfect sense. Stop being an edgy contrarian and get over noGC autism
>>
>>60838473
I understand what you're saying. They're a pain in the arse to track down.
But I personally don't experience those problems very often as I'm a game dev.
>>
>>60838464
you are wrong.
header files are a good thing, the only problem is that some people don't use them correctly.

Say you have a proprietary software library you want to sell to people.
You can compile the source files and give them your header files.
The programmers will know how stuff works and how to interface it with their project, but they can't study how it is implemented.

If the source code is free, people can still read the header files and understand the project and if they need to modify a behavior, they can dive into specific functions and thus save a lot of time.

Header files give the technical benefit of reducing compile time, but they also force programmers to document their code.
Most IDE's have solved the problem of writing the same function in two places, so it is not a tax on the programmer.
Another great benefit is you can very collaborate.
You can write the skeleton of a project fairly quickly and then delegate the parts out to different people.
If the API of every function is planned out, you can use the function as if it works to get something up and running as fast as possible.

I think header files are great.
Programming languages that don't have them usually lead to poorly documented, poorly structured and poorly written programs.
>>
Header files in C are a bad design not least because C's macro system is bad: it works via token substitution, not on an AST level. This means:
It barfs on circular includes
It means that the same stuff is compiled multiple times
A seemingly short and simple program might grow to a gigantic behemoth due to a few includes.
It is incredibly limited (compared to what the gold standard of macros – Lisp – can do).

Header files are bad because they are files. And these files are separate from the actual code. Or not: nobody is preventing you from putting code in the header as well. Why shouldn't the header be in the same file as the source code? There is no solid technical reason for not doing this unless single-pass compilation of each compilation unit is required.

Headers are bad because a non-naive compiler can jolly well figure out forward references of symbols without having these be pre-declared. Predeclarations are only useful if a multi-pass compiler is not an option for some reason. Pre-declarations have no value for a human reader (it's a massive DRY violation), and add too little value for a compiler.
>>
“Without headers we can't link against libraries” – I'm sure that's true for C and descendants (which unfortunately are ubiquitous), but this doesn't hold for other languages.

A simple alternative is to directly use the source code of a library to extract the interface (this is how many scripting languages like Perl or Python kind of work).

This may not be desirable in closed-source environments, where the compiler output could be used to link against (which is roughly how Java works, where .class files contain the interface alongside the executable bytecode).

The key point is not that no link specification exists, the key is that this specification isn't written by humans.

“Without headers we can't share things (functions, macros, classes) between files” – yes we can, with things like namespaces and modules containing these things. Let's say I have a #define PI 3.1415 in some C code. To share that definition between my source files, I'd have to #include "my_math_constans.h" or something. Python's solution from math import pi which loads the math module and imports the pi symbol from that module into the current scope works at least just as well.
>>
what is a good source to learn QT? I'm kind of struggling trying to set up a very simple UI.
>>
>>60838592

With a modules system your compiler will either embed the public symbols to interface with iin the object code or just spit out a compiler-legible interface file alongside the object code.
>>
>>60838538
>A prime example of this is when you need to overload the basic arithmetic operators and their implementations are identical save for the operator.
C++ is more explicit in this manner, but is it really a problem for anyone other than the text editor?
>D's arrays are vastly better than C++'s arrays
C++ have a lot of ways to store data.
int arr[10];

is reffered to as a c-style array which in this case stores 10 ints.
This is kept in the language because it is the most simple form of an array structure and can be useful in some situations.
C++ have vector which is what you are describing.
Strings are a vector of chars, so it is the same in this regard.
>>
In fact C++'s stdlib is so bad no serious game companies use it. EA uses their own stdlib for C++

Gives you an impression how much of a clusterfuck the language has become.
>>
>>60838675
D has fixed length arrays too, which you are describing
>>
>>60838592
Those are good points actually.
>>
>>60838656
Qt have good documentation, read it.
Specifically read up on signals/slots.

For a simple gui, you want an action to be called when you press a button or when a slider changes or maybe update the gui when you complete a function.
Instead of calling a function, you emit a signal.
If the signal is connected to a slot, the slot function will be called.
>>
>>60838640
>>60838635
Which is why newer more modern languages have modules. Modules are coming to C++ soon. Clang and MSVS have their own implementation of modules system but the standard is yet to be voted
>>
>>60838592
So Header files are a poor man's javadoc? If you solve the "same function twice thing" by having a program scan through your source files to autogenerate documentation, it should also pick up docstrings and properly formatted comments.
>>
>>60838770
I don't know if it is a poor mans javadoc, it is basically the same thing.
A lot of projects use doxygen which generates good documentation which is searchable and easy to read in the code or in a browser depending on what you prefer.

"same function twice" is a wrong mentality.
You declare a function and then you implement a function.
The correct way to do it is by declaring it in a header file, usually inside a class.
Here you write the javadoc like comments over each function.
Then you implement the function in the source file.
Usually there is no need for making comments in the source files as everything should be explained in the header file.

I know the same function is written two places, but I don't personally write it twice.
I write it once in the header and the IDE inserts it in the source file (or rather, it autocompletes it after the first letter, but basically same thing).
>>
File: MR69Qlc.png (363KB, 761x1032px) Image search: [Google]
MR69Qlc.png
363KB, 761x1032px
>>60836786

You'd be better off making it with a reference wrapper, to avoid that pointer frizzle frazzle later in life.

Derived dev;
std::vector<std:: reference_wrapper<Base>> vec;
vec.push_back(std::ref(dev));
vec[0].get()==dev;


>>60837456
>int x = 1
Declaration to default construction, then copy assignment

>int y = 1; int x(y)
Copy Construction

>int x(1)
Construction by value

The semantics matter, they define the behavior (if define by coder) as to how data should be handle to create an object. What you're referring to is compiler performing optimizations if and when it can as long as it didn't violate the end behavior of the code.
>>
>>60838973

>std::reference_wrapper
I don't get it, what is this for?
>>
>>60838973
Oh, that's much better with the ref wrapper. I just noticed that I cannot use push_back but had to use emplace_back instead.

>>60839113
Basically, you it's a way to create containers of references. Following the previous case:

g++ -std=c++1z animal.cpp && cat animal.cpp && ./a.out 
#include <memory>
#include <vector>
#include <iostream>

struct Base {
int bval;
Base(int v) : bval(v) {}
virtual void talk() { std::cout << "base " << bval << '\n'; }
};

struct Derived : Base {
int dval;
Derived(int a, int b) : Base(a), dval(b) {}
virtual void talk() { std::cout << "derived " << dval << '\n'; }
};

int main() {
Derived d(1, 2);
Base b(3);
std::vector<std::reference_wrapper<Base>> vec;
vec.emplace_back(std::ref(d));
vec.emplace_back(std::ref(b));

for (Base& e: vec) {
e.talk();
}

return 0;
}

derived 2
base 3
>>
>>60839237

I don't see why I need this. Why shoudn't I use a pointer?
>>
>>60839505
Using reference specifies that the contained objects are non-nullable. This is important if you start passing around references of your vector to other functions:

void foo_ref(std::vector<std::reference_wrapper<Base>>& v) {
//v[0] = nullptr;
//v[0] = std::reference_wrapper<Base>(nullptr); neither will compile
}

void foo_ptr(std::vector<Base*>& v) {
v[0] = nullptr;
}
>>
>>60830557

> reading somebody's code
> see somebody initialize an int in syntax I don't recognize
> immediately freeze
> literally shaking
> uninstall gentoo
> get gun
> point at my head
> pull trigger
>>
>>60838947
But header files make compilation significantly harder since you are exposed to low-level linker errors during compilation.

Also, often the compiler forces you to put template or inline functions in header files, meaning you don't actually have a separation between the two.

I generally find header files to be a major headache in C and C++. They are the only modern languages that force you to deal with that fuckery. If all you want is free-standing type declarations, use free-standing type declarations, instead of doubling the number of files in a project.
>>
>>60840321
you don't double the line numbers of a project by having header files.

The template situation is fixed by using the extern keyword, but yes, it was a fuckery back in the day where you included the source file.

As for linker errors, you will always have a problem if your development environment is not setup correctly.
I use cmake on my projects and that takes some of the pain away, but I will not claim to never spend time on this.

But if cmake is the hardest part to learn about C++, then it is not really a problem is it?
>>
What would anon do to fix C++?
>>
>>60840847
namespace std2
Burn everything and start again
>>
>>60841075

what's wrong with stl? Only thing that comes to mind immediately is vector<bool>
>>
>>60830440
B A I T
A
I
T

P A J E E T
A
J
E
E
T
>>
>>60841135
not him, but steams design is a bit fucky, and half the older APIs aren't very religious about following minimal RAII patterns.

> declare
ofstream f;

> write:
f << "hello /g/";

> oh shit, have to call
f.open(...);
first
> we're good, right?
> nope, have test if (f) now
> (finally there for real now)
> call
f.close();

> can still say
f << "oh fugg";
here.
> wtf
>>
>>60841400

Good point.
>>
>>60837456
It acts the same because int is a POD type and 1 is a numeric literal
>>
>>60830378
Can we talk about how moronic it is that C++ uses operator overloading for I/O?
>>
>>60841719

I agree, the whole << >> thing is ugly as shit.
>>
>>60833418
So did Epic, plus they also made a prepreprocessor
>>
>>60841724
Someone clearly was designing C++ and said "Woah you know what'd be cool? If we could do I/O using << and shit instead of functions" and didn't actually think about what he was doing.
>>
>>60841859

That's a trap that a lot of C++ developers fall into.
Operator overloading is wonderful when done right (+-*/ really does mean arithmetic, * -> really does mean dereferencing, [] really does mean indexing) but people use it for shit that doesn't even resemble its original purpose.
>>
>>60838635
>simple source file can grow giant from on include
>but also, put your definitions with declarations
>>
>>60841952
true
>>
>>60841966
Now it will be 10x if not more bigger
>>
>>60838635
>It barfs on circular includes

The compiler/linker would produce an error about having multiple definitions.

>It means that the same stuff is compiled multiple times

You include preprocessor statements to prevent that.
>>
>>60842971
>preprocessor
yuk
>>
>>60833403
>Will be replaced by languages like Swift, Rust etc..
HAHAHAHAHAHHAHA

No.
>>
>>60843056
YES!
>>
this is a test
this is also a test

but this is not a test


>>
File: its_free.jpg (9KB, 300x121px) Image search: [Google]
its_free.jpg
9KB, 300x121px
>>60843112
 The license agreements of most software companies try to keep users
at the mercy of those companies. By contrast, our General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. The
General Public License applies to the Free Software Foundation's
software and to any other program whose authors commit to using it.
You can use it for your programs, too.
 When we speak of free software, we are referring to freedom, not
price. Specifically, the General Public License is designed to make
sure that you have the freedom to give away or sell copies of free
software, that you receive source code or can get it if you want it,
that you can change the software or use pieces of it in new free
programs; and that you know you can do these things.

To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.

For example, if you distribute copies of a such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must tell them their rights.

We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.

If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.



>>
File: kill.gif (747KB, 248x200px) Image search: [Google]
kill.gif
747KB, 248x200px
>>60833403
>>60833403
>banks can't go bankrupt.
I pray every day that distributed banking practices such as those used in currencies will continue to devalue international currency while inflating their own value until a point arrives that every major world bank collectively fails due to their worthless currency and the central bankers that pull strings worldwide are ruined by technology
>>
>>60843311
>I pray every day that distributed banking practices such as those used in currencies
>currencies
I meant cryptocurrencies
>>
>>60843311
Never gonna happen, since the said currencies are backed by armies and police.
>>
>>60839237
Weird I've used it with push_back flawlessly before. Utilized it to populate a struct's vector with all the local member hash sets to make it a simple for loop to check global and local collisions
>>
File: sad.jpg (185KB, 1500x1639px) Image search: [Google]
sad.jpg
185KB, 1500x1639px
>>60843347
I can still hope
>>
>>60843372
When banks fall they will buy nukes and bomb everybody, because fuck you all, it's your fault
>>
Unrelated but didn't know where to ask.

I want to convert a video to WebM with VP9.
I want to use FFMpeg but it seems I have to compile it first with vpx enabled or something like that but I can't compile and so is there a build with vpx enabled I can download?
>>
>>60843527
Why can't you compile?
>>
>>60830557
>it has 2 fucking standard libraries
What? There is only one. If you refer to boost then it's not the standard lib. Parts of boost sometimes get assimilated into the C++ standard. Some parts of it are really good while other parts are of subpar quality.
>>
>>60830378
Nah it's quite nice and I like it more than C and C#. The problem with C++ is that retards use it the wrong way and then blame the language. They should just stick with their scripting languages.
>>
>>60838678
The standard does not provide implementations of the standard lib. They only specify what needs to be included to fulfil the ISO standard. If companies roll their own standard lib it's because they aren't satisfied with the implementation that came with the compiler.

In general though companies that roll their own standard lib did/do so for several reasons. One reason is because C++ programmers are extremely conservative and wont consider any lib younger than 15 years as stable. Another is that some code bases are 15 years older than the average age on /g/ so companies made their own string library because it wasn't a part of the standard back then as many other things that are now part of the standard.
>>
>>60830701
>le java is fast meme
In terms of performance:
C > C++ >>> C# >>>>>>>>>>>>>>>>>>>>> Java
>>
>>60845588

benchmarks?
>>
File: 1331793471404.jpg (42KB, 604x453px) Image search: [Google]
1331793471404.jpg
42KB, 604x453px
>people complain that C++ is bloated
>same people also complain that the stdlib is too small
why are some people so dumb?
>>
>>60845661
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=gpp&lang2=java
>>
>>60845755

http://benchmarksgame.alioth.debian.org/u64q/csharp.html
Looks pretty even between Java and C# to me.
>>
>>60845797
http://benchmarksgame.alioth.debian.org/u64q/compare.php?lang=csharpcore&lang2=gpp
Thread posts: 165
Thread images: 14


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.