News for hackers. Stuff that matters.
Re:Can you use a class in C? by tragomaskhalos on Sunday August 13, 2023 @06:38AM (#37108595)
Your allocation method - malloc + cast - may work for simple classes but overall it's a serious no-no; think you should either be using new/delete, or, if sticking with malloc /free, use placement new and an explicit destructor call respectively.
Re:Can you use a class in C? by jwatzman on Sunday August 13, 2023 @06:43AM (#37108629)
The article discusses constructors and how to make them work under "Linking the C++ standard library".

I wonder if placement new would run into the same linker problem that the article mentions -- I'll have to try it at some point :)

Re:Can you use a class in C? by krater23 on Sunday August 13, 2023 @11:07AM (#37110680)
And the stupidest thing, he uses this malloc in a .cc file, where it would no issue to just use new. Thats the point where I stopped reading. After auto main() -> int { ... }

I didn't supposed that anything really meaningful can come...

Re:Can you use a class in C? by intelVISA on Sunday August 13, 2023 @07:04PM (#37115528)
Thanks, you spared me the horrors.