1

I'm a 13 year old who's trying to learn C++. I bought C++ Primer and I came across something confusing for me:

struct Sales_data {/**/ } acum, trans, * salesptr = nullptr;
    struct Salees_data {};
    Salees_data accumm, transs, * salessptr;

I do understand what is a struct and class but I have no idea what this statement will do. Will it create objects of the Sales_data struct, or it will create variables inside the Sales_data struct?

  • Recomended google: "Nested structs". Here is an similar question. https://stackoverflow.com/questions/8284167/nested-structures-in-c-and-c – Frebreeze Sep 29 '21 at 20:01
  • there is no nested struct. just some strange indent. – apple apple Sep 29 '21 at 20:01
  • You are very right. My bad! See Ted Lyngmo's answer. TLDR; One liner declaring two objects SaleesData. One object pointer to a saleesData obj (null) – Frebreeze Sep 29 '21 at 20:07

1 Answers1

2

This defines a Sales_data struct and

  • acum and trans - Two Sales_data instances
  • salesptr - A Sales_data pointer, initialized to nullptr
struct Sales_data {/**/ } acum, trans, * salesptr = nullptr;

This defines a Salees_data struct and

  • accumm and transs - Two Sales_data instances
  • salessptr - A Salees_data pointer, uninitialized
struct Salees_data {};
Salees_data accumm, transs, * salessptr;

or it will create variables inside the Sales_data struct?

No, there are no member variables in either of the class definitions.

I say class definitions because structs are classes too, only with a different default access specifier (public instead of private).

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108