5 ms·
You mean except booleans, integers, floats, pointers, free functions, namespaces, templates and lambdas?
by lultimouomo 8y ago
You mean except booleans, integers, floats, pointers, free functions, namespaces, templates and lambdas?
- gpderetta 8y agoAlso a class in C++ is by default exactly the same as a struct (except for default access control which is a minor thing). An OOP style class would be any class type (including struct) with virtual functions which you would have to opt in.
- asveikau 8y agoI agree with your sentiment but the lambdas do get treated as anonymous classes overloading operator ().
- kllrnohj 8y agoNot really true. Lambdas can be converted to a class overloading operator() (such as std::function), but they are not inherently that. You can use them as just function pointers, too. Example: #include <cstdio> void call_func(void(*func)()) { func(); } int main(int argc, char* argv[]) { // Lambda can be converted to a function pointer call_func([]() { printf("hello as a function pointer\n"); }); }
- asveikau 8y ago> but they are not inherently that. I am fairly certain I have had error messages and disassemblies that suggest otherwise. This may however be an implementation detail. > You can use them as just function pointers, too. Yes, I know this. It only works when there are no captures. And AFAIK once there are captures you start getting object code that looks a lot like you put those captures into an anonymous class. (When not inlined.)
- slavik81 8y agoYou can get that sort of behaviour from any class by implementing the conversion operator. I assume that lambda implements `operator(void(*)())` so it is implicitly convertible to a function pointer.
- MichaelMoser123 8y agoyes, you can do a C++ program with functions only + integers and array of integers. technically that's C++. Very apt observation! I still guess that the main entities in your c++ program will be classes (not POD) And I still maintain that most people treat class libraries (such as STL) as given and do not inspect how they are implemented and do not consider what constraints / alternatives do exist. One example: the std::dequeue is a dynamic array, and you can't quite tune the size of the inner array easily by means of template or instance parameters - no one cares. Also many people happily use the shared_ptr class and don't even know that it takes very expensive atomic operations to do the reference counting; I would have expected a template parameter that could determine if shared_ptr is meant for multithreaded use or not. Most people don't care and happily use the shared_ptr. Also there are no intrusive linked lists in STL (well, there are in boost) I can go on and on about the STL (and other widely used libraries if you care) and I still suspect that they get away with these "issues" in a widely used library because people are used not to question library implementations and treat them as frigging black boxes.