|
pokeyman posted:is the hint "car extends vehicle" code:
|
# ? May 29, 2016 21:01 |
|
|
# ? May 26, 2024 09:28 |
|
go would be an absolute nightmare for anything involving business logic / business objects, imo
|
# ? May 29, 2016 21:03 |
|
C++: I have an Widget class and a Button class that inherits Widget. Widget has an abstract draw method that returns a pointer to a char array, Button implements it. eventually I'm going to want to define more kinds of widgets than just Button. I want to be able to fill an std::vector with a bunch of Widgets and call their draw methods without caring about their types. in c# I would use an IWidget interface and override the draw method in the child classes but I'm bad at c++. is there an equivalent I can do in C90/C++ 2.0/whatever this Watcom compiler understands or how should I be doing this?
|
# ? May 29, 2016 21:14 |
|
that's what virtual methods are
|
# ? May 29, 2016 21:16 |
|
class widget { public virtual char* draw() = 0 or maybe virtual public draw() = 0 i forget } class button { public virtual char* draw() { return &the_thing } } there i wrote it for you
|
# ? May 29, 2016 21:20 |
|
don't mix virtual methods with stl containers unless you like being very careful about pointer ownership or at least that's how things used to be, maybe it's better now that there are smart pointers in the stdlib
|
# ? May 29, 2016 21:21 |
|
Luigi Thirty posted:C90/C++ 2.0/whatever this Watcom compiler understands
|
# ? May 29, 2016 21:22 |
|
lol then
|
# ? May 29, 2016 21:23 |
|
lol at using haskell or go for anything
|
# ? May 29, 2016 21:33 |
|
GameCube posted:class widget oh I was trying to do that with a Button in a std::vector<Widget> and it was executing the parent class' draw method instead probably because I didn't declare the Button's draw method as virtual too Soricidus posted:don't mix virtual methods with stl containers unless you like being very careful about pointer ownership lol rip, back to arrays
|
# ? May 29, 2016 21:35 |
|
MALE SHOEGAZE posted:go would be an absolute nightmare for anything involving business logic / business objects, imo https://www.youtube.com/watch?v=nYscs78R5Fs
|
# ? May 29, 2016 21:46 |
|
Luigi Thirty posted:oh I was trying to do that with a Button in a std::vector<Widget> and it was executing the parent class' draw method instead probably because I didn't declare the Button's draw method as virtual too if youve used java, you can think of it as 'java decided that methods should always be virtual'
|
# ? May 29, 2016 21:48 |
|
basically if you're using classes with inheritance in c++ then you want to always use pointers, partly because that's the way you make virtual methods actually be virtual, and partly because horrible things happen if you try to put a Button in a collection (or array) of Widgets when sizeof Button != sizeof Widget
|
# ? May 29, 2016 21:56 |
|
Luigi Thirty posted:oh I was trying to do that with a Button in a std::vector<Widget> and it was executing the parent class' draw method instead probably because I didn't declare the Button's draw method as virtual too there's no reason you can't put a class with virtual functions in an stl container wtf
|
# ? May 29, 2016 21:58 |
|
Soricidus posted:don't mix virtual methods with stl containers unless you like being very careful about pointer ownership wait why not i know youre not supposed to subclass containers b/c of virtual dtors but beyond that ???
|
# ? May 29, 2016 22:31 |
|
always virtual your destructors
|
# ? May 29, 2016 22:59 |
|
Luigi Thirty posted:oh I was trying to do that with a Button in a std::vector<Widget> and it was executing the parent class' draw method instead probably because I didn't declare the Button's draw method as virtual too people have kinda already said this, but you need to use std::vector<std::unique_ptr<Widget>>, or std::vector<Widget*> (if something else has ownership). If you assign a Button to a Widget (not pointers), the button stuff will get sliced off. there's nothing wrong with using stl vectors for this. if std::unique_ptr isn't available you should probably write your own. a basic implementation shouldn't be complicated.
|
# ? May 29, 2016 22:59 |
|
looks like I have auto_ptr but unique_ptr was added in C++11
|
# ? May 29, 2016 23:03 |
|
why would you NOT want pointers in a container
|
# ? May 29, 2016 23:03 |
|
Luigi Thirty posted:looks like I have auto_ptr but unique_ptr was added in C++11 no. stop. don't. even in the special hell you are stuck in you can use boost
|
# ? May 29, 2016 23:22 |
|
btw if you're going to use boost anyway, it's got ptr_vector
|
# ? May 29, 2016 23:28 |
|
Brain Candy posted:no. stop. don't. even in the special hell you are stuck in you can use boost now u have 2 problem
|
# ? May 29, 2016 23:29 |
What's wrong with boost?
|
|
# ? May 29, 2016 23:33 |
|
like every other part of c++, I used it 10 years ago
|
# ? May 29, 2016 23:34 |
|
MALE SHOEGAZE posted:
this is called a tagged gounion
|
# ? May 29, 2016 23:37 |
|
pokeyman posted:this is called a tagged gounion Pronounced "gown-yawn".
|
# ? May 29, 2016 23:56 |
|
Zemyla posted:Pronounced "gown-yawn".
|
# ? May 30, 2016 00:03 |
|
pronounced "bunion"
|
# ? May 30, 2016 00:13 |
|
Luigi Thirty posted:I want to be able to fill an std::vector with a bunch of Widgets and call their draw methods without caring about their types. in c# I would use an IWidget interface and override the draw method in the child classes but I'm bad at c++. is there an equivalent I can do in C90/C++ 2.0/whatever this Watcom compiler understands or how should I be doing this? as long as you make it a std::vector<Widget *> (or Widget&, or a smart pointer to a Widget) it should work fine since you're passing around pointers and can make Widget::draw() virtual just be sure you have well-established ownership rules for your objects, for example in Cocoa views are owned by their superviews, so you need to take ownership before removing a view from its superview if it needs to stick around
|
# ? May 30, 2016 00:32 |
|
Soricidus posted:basically if you're using classes with inheritance in c++ then you want to always use pointers, partly because that's the way you make virtual methods actually be virtual, and partly because horrible things happen if you try to put a Button in a collection (or array) of Widgets when sizeof Button != sizeof Widget and all that's because Stepanov said software must be written from the algorithm outward, and decided to enforce that with the utter poo poo design of the C++ Standard Template Library for any real-world development
|
# ? May 30, 2016 00:36 |
|
christ, what an rear end in a top hat
|
# ? May 30, 2016 00:46 |
|
what does it mean to design from the algorithm outward
|
# ? May 30, 2016 00:49 |
|
Soricidus posted:basically if you're using classes with inheritance in c++ then you want to... drink a lot of whisky to deal with the pain of both C++ and inheritance
|
# ? May 30, 2016 01:20 |
|
anthonypants posted:gee-onion the stallman-approved reimplementation of Tor
|
# ? May 30, 2016 01:24 |
|
phone posting but jdk 9 will have standalone modules that include everything you need to run
|
# ? May 30, 2016 01:56 |
|
go as imagined: imagine C but we got rid of malloc and free we got rid of include files and Makefiles we added a built in list, hash table, and unicode string type we added tools to auto-format your code, as well as fix old syntax we didn't get to exceptions, or generics, but they're hard to do and we're used to life without them but we did like pipes and processes in unix so we added a lightweight system to run little snippets of code which can use pipes oh and cross platform builds, it doesn't sound that awful compared to C (i mean golang only looks weird when you ignore all the other things like limbo or alef or plan-9 c, it's kinda incremental) go in reality: what do you mean you wanted a repeatable build or stable dependencies *slaps github urls everywhere imports before making GBS threads pants*
|
# ? May 30, 2016 02:08 |
|
FamDav posted:phone posting but jdk 9 will have standalone modules that include everything you need to run im embarrassingly excited for java 9 not that theres a level of excitement that wouldnt be embarassing
|
# ? May 30, 2016 02:32 |
|
FamDav posted:phone posting but jdk 9 will have standalone modules that include everything you need to run this is cool tef posted:go as imagined: this is true
|
# ? May 30, 2016 02:34 |
|
on the other hand it's also not really an insurmountable problem in the short term - fork your dependencies then pull from master when something comes up that you need.
|
# ? May 30, 2016 02:35 |
|
|
# ? May 26, 2024 09:28 |
St Evan Echoes posted:its the whipcrack of management's latest vim
|
|
# ? May 30, 2016 02:53 |