Car car = new Car();

>Car car = new Car();

Attached: 1518169463683.jpg (224x224, 8K)

you forgot your asterisk. here ya go
*

He overloaded operator=()

hired

>Old New = new Old();

Attached: 1489296633761.jpg (640x480, 45K)

> make pos software for dealers in wy
> unironically write code like this
I laugh every time

auto car{std::make_unique(new Car())}

Really, Car is an abstract class and new Car() should never be called by client code.

What you really want is a factory method to produce a car of a certain make and model, or to instantiate a car of a certain make and model directly like such
Car car = CarFactory(make=Honda, model=CIVIC_2019)

Doesn't Car car; already create an instance of Car?

Can I just mention how much I fucking hate java? I'm a technician and have to complete this Networking course, which I'm enjoying, but we have to learn this piece of shit language. I'm almost complete with the assessments (for any Australians out there it's TAFE) and they're mainly "copy paste this code, run it and explain the output".

I also have to learn python, which I'm looking forward to, but if it's anything like this dumb shit language I'm going to blow my fucking brains out.

Not in java

in c++ yes. it will create a Car object on the stack and default construct it.
new Car() allocates memory on the heap (that's what the new keyword does) and constructs it. then you get a pointer to it.

Car *car = (Car*)malloc(sizeof(Car)); is the only correct way

But you can do all sorts of fun, nonsensical things if Car is a pointer type.

lar lar in the car car

Attached: 1523028443952.jpg (600x900, 55K)

what's the difference between that and new? besides new being shorter

You can't new in C

malloc only allocates memory, without initializing it.
new Car() also calls the constructor

>casting the return value of malloc

t.brainlet

It should be
auto car = std::make_unique();

Also, malloc has no alignment restriction so you might need to manually align your Car if it needs a certain alignment.

Welcome to user's guide to Swift™

Let car: Car? = Car()

Also make Car objective-c compatible with the @objc annotation/NSObject inheritance.

Bonus points if you declare every single property in Car as implicit unwrapped optional.

Add semicolons at the end of the lines for extra suffering.

Depends on the compiler. Vcc bitches about the strangest of things. It jumps at me for not declaring variables at the start of a block

>sizeof(Car)
>not sizeof(*car)

No.
In C, by standard, void* is implicitly casted to any other pointer type

sizeof(Car) is converted to a literal at compile time. sizeof(*car) has to be computed every time while running.

t.brainlet
sizeof is always a constant expression. C and C++ as no dynamic types, thus type of *car must be explicitly known compiletime, and so does its size.

in C there is no runtime that could inspect the type and its size at runtime. the compiler knows that car points to a Car and it knows the size of that, so that expression is evaluated at compile time.

auto newcar = new car{&&car_factory};
delete newcar;

var car = new Car();

c# master race

technically there are dynamic types in C++.

class Base {
int x;
};

class A : Base {
float y;
}

class B : Base {
bool y;
}

Base *f() {
if ((rand() % 100 - 50) > 0)
return new A();
else
return new B();
}


but I know what you mean.

>const car = new Car();

struct Car *car = malloc(sizeof(struct Car));

Attached: 1532111433072.gif (540x540, 577K)

No, thats just runtime polymorphism, not dynamic types. The receiver of a Base* does not know the original type.
If you wanted to show a real exception from this rule you would've used RTTI, which is actually kinda like it, although obviously stuff like sizeof doesn't work with it, since sizeof doesn't evaluate anything runtime, and RTTI, as its name says, is runtime.

>Not using the "auto" keyword.
>Using the "new" keyword.
costanza.jpg

cool

This.

In C++, sizeof is always a constant expression.
In C89, sizeof is always a constant expression.
In C99, sizeof is a constant expression except when you use it on a VLA.

unsigned wank(unsigned a) {
char b[a];
return sizeof b;
}

Beginner here, what's wrong with Car car = new Car();?

Being employeed

Hmm, let me try.
Vehicle car = VehicleFactory.CreateObject(VehicleType.Car);

>using auto

Correctly declare the type of your variables you stupid little shit, auto is for pussies.

>auto is for people who have never maintained anything larger than a toy project

ftfy

New gives you a pointer to an object, not an object. Car *car = new Car();

Also car is the brother of cdr.

var was a mistake

I'm unironically learning more from this thread than I've learned in two and a half years at CompSci in uni. Please continue.

Button button = (Button) rootView.findViewById(R.id.button);

Absolute state of Java/Android devs

Attached: Tyrese_Bogdanoff.jpg (640x531, 44K)

val car = Car()

This has been changed in support library 26.

NEET neet = new NEET();

Ywah i never got why java does this

(my (other (car (is 'cdr))))

I fucking hate this syntax, yet I'm forced to learn thisnfor my job. I also need to learn angular...

fucking kill me already

Attached: 1428378365078.jpg (800x600, 66K)

There is always another way.

Attached: 5.jpg (306x422, 46K)

Why shouldn't i do that?
I do it only because youcompleteme bitches when i dont do it.

more like
auto car{std::make_unique()};

Doesn't change anything, = when declaration is initialization, operator= doesn't run.

True, but distinguishing initialization from assignment makes it clearer though.

std::unique_ptr myCar = std::make_unique();

>what is Kotlin

dude
std::unique_ptr my_car{std::make_unique()};

Attached: 1533952893657.png (645x729, 87K)

Car car = Car.getInstance();

in C++ you should cast it, in C it's implicit so there's no need

let car = Car::new();

Attached: rust dev.jpg (680x788, 72K)

let mut car: Box = Box::new(Honda::new()?);

HAI 1.0

BTW
THIS WILL BUILD A CAR
TLDR

CAN HAS CAR?
CAN HAS GAS?
CAN HAS MILEAGE?

I HAS A HONDA ITZ A CAR
HONDA R "BLUE"
I HAS A TANKOFGAS ITZ A GAS
TANKOFGAS R 10
I HAS A MILEAGE ITZ A NUMBR
MILEAGE R 0

IM IN YR LOOP NERFIN YR TANKOFGAS TIL BOTHSAEM TANKOFGAS AN 0
TANKOFGAS R DIFFOF TANKOFGAS AN 1
MILEAGE R SUMOF MILEAGE AN 20
IM OUTTA YR LOOP

VISIBLE SMOOSH "You travelled a total of " AN (MAEK MILEAGE A YARN) AN " miles with you " AN (MAEK HONDA A YARN) MKAY

KTHXBYE

Attached: 0546pepe.png (350x338, 63K)

that doesn't even make sense you fucking brainlet

Can't new in C#, either.

wat

Retarded or bait?

class Car
{
EngineLayout engine_layout;
float engine_displacement;
Drivetrain drivetrain;
const constexpr const strconst std::string const const name_manufacturer;
const constexpr const strconst std::string const const name_model;
Year year;
VIN vin;
};

class CarManager: public Singleton, IManager
{
public:
CarManager() = default;
virtual ~CarManager() = default;

void Initialize() = auto_define;
void CleanUp() = auto_define;

// The C++57 standard introduces a way to use both brace styles at once
template
void AddCar(const_workaround std::string& name_manufacturer,
const_workaround std::string& name_model, uint128_t vin) {
{
std::private_workaround()::GetInstancePtr()->m_cars.emplace_back(
{EngineLayout::I4, 1.6f, Drivetrain::FWD,
name_manufacturer::grab_const(), name_model::grab_const(),
Year::ToYear(YearOfManufacturing + 1), vin}
// all cars in 2057 use I4 1.6Ls to reduce emissions, EVs don't exist because elon musk was murdered
);
}

static CarManager& GetInstance() = auto_define;
static CarManager* GetInstancePtr() = auto_define;

private:
std::vector m_cars{{{}}};

};

int128_t numain(int128_t argc, const_workaround std::vector args)
{
auto cm{std::make_unique(new CarManager())};
cm.AddCar("Toyota", "Corolla", 20xx5YFBURHE9JP746410);

return 0ll;
}


c++57 ended up being the best release yet, you guys should get it within the next few decades

>Jow Forums cretins trying to discuss software architecture
Let me grab the popcorn.

>const constexpr const strconst std::string const const

Alright we get it.

all that work and it still gets ignored by const_workaround

All I got from this weak "joke" is that you have absolutely no idea how generics work.

There are waaaay worse things you could be doing for a job than angular

template
class SingletonBase{

SingletonBase();
~SingletonBase();

public:
static T & GetInstance(){
static T instance;
return instance;
}
};

using CarSingleton = SingletonBase;

int main(){
auto & car{ CarSingleton::GetInstance() };

car.Init();
car.Drive();

return 0;
}

Attached: 1533850563677.jpg (500x590, 39K)

i mean in theory it could work

Whoosh

Go read some books man, you're wasting everyone's time.

>template functions declared but not defined
>using CarSingleton = SingletonBase;
user, what the fuck are you doing?

the joke was literally that none of that could work but aight

You can try to fool me but you can't fool yourself bud.

Wait a minute bro. What's the point of having a singleton if you still need to pass it around everywhere and it's not static?

mhm keep telling urself that

the point of a singleton is that you pass it around everywhere instead of a global

(defun Car
(car (cdr (cdr (string-split "my other car is a cdr")))))

Attached: _yagomengomen.png (384x384, 160K)

But why would it need to be a singleton then? Can't you just make a single instance and pass that around?

>Can't you just make a single instance and pass that around?
In well designed architecture

Kangz kang = new Kangz()

We wuz = kangz()

Underrated.

>bool checked = ((CheckBox)sender).Checked;
:^)

What a normie
typedef struct Car Car;

typedefing structs is for faggots

let car = Car::new();

>normie
Oh wow, that was a good one. You sure do fit in around here, user. I'm glad you aren't one of those lowly normies. We are so cool!

do you guys do shit like
auto variable_name{size_t{0}};

as well or am I autistic

How bad is RTTI (performance decrease over never invoking it at all)? I remember being a performance stickler and would avoid invoking it as much as possible. Been awhile since I coded and want to relearn C++.

Bad probably isn't the right word. Just curious from a performance standpoint. I know it's probably impossible to avoid in many cases.

depends what you're using it for. a dynamic_cast shouldn't be any more expensive than a virtual function call.