About 106,000 results
Open links in new tab
  1. c++ - How to use a struct inside another struct? - Stack Overflow

    I have somewhat like the following code running for a while live now and it works. // define a timer struct lightTimer { unsigned long time; // time in seconds since midnight so range is 0-86400 …

  2. data structures - Should I use structs in C++? - Stack Overflow

    Sep 28, 2010 · The difference between struct and class is small in C++, basically only that struct members are per default public and class members are per default private. However, I still use …

  3. When should you use a class vs a struct in C++? [duplicate]

    This means that one can use a struct in an include file that can be #include into either C++ or C so long as the struct is a plain C style struct and everything else in the include file is compatible …

  4. What are the differences between struct and class in C++?

    You can use template<class T> but not template<struct T>. Note also that the C++ standard allows you to forward-declare a type as a struct, and then use class when declaring the type …

  5. c++ - Using struct in different .cpp file - Stack Overflow

    Jul 30, 2011 · struct MyStruct { int messageID; int tempVariable; }; In your main.cpp, this is where you actually use the struct: void someFunction() { struct MyStruct tempStruct; // do something …

  6. How to use a defined struct from another source file?

    Jan 21, 2018 · To access the same instance of the struct across the source files, you can still use the extern method. // Definition.h struct test_st { int state; int status; }; // File1.c #include …

  7. Can a struct have a constructor in C++? - Stack Overflow

    Sep 10, 2023 · The reason for having struct in C++ is C++ is a superset of C and must have backward compatible with legacy C types. For example if the language user tries to include …

  8. c++ - When to use a namespace or a struct? - Stack Overflow

    Apr 10, 2010 · In C++ a struct is exactly the same as a class, except structs are public by default. Classes are private. So whenever you want to group free functions together use a namespace. …

  9. Proper way to initialize C++ structs - Stack Overflow

    Jan 21, 2017 · In C++ classes/structs are identical (in terms of initialization). A non POD struct may as well have a constructor so it can initialize members. If your struct is a POD then you …

  10. Return a `struct` from a function in C - Stack Overflow

    It's arrays that you can't return from functions (or assign), since arrays are not first-class types in C. But a struct is a properly first-class type, and can be assigned, passed, and returned with …

Refresh