0

The following two classes are absolutely equivalent in every way except their name:

struct s
{
   int x;
};

class c
{
public:
   int x;
};

Is there a difference in speed between reading from a struct then a class?

For example,

is

int y = s.x

Slower then

int z = c.x

to run? Is one of them less efficient to read from?

Jett t
  • 13
  • 2
  • 1
    TL; DR: No. There is no difference, given your example. Or any other, come to think of it. – Spencer Sep 12 '22 at 12:55
  • 2
    Nothing is stopping you from looking at the disassembly. – Quimby Sep 12 '22 at 12:55
  • 6
    `struct` and `class` in C++ is *exactly the same*, except for default access permissions and default inheritance. – Jesper Juhl Sep 12 '22 at 12:57
  • https://en.cppreference.com/w/cpp/language/as_if – Marek R Sep 12 '22 at 12:58
  • 1
    imho in it was a mistake to introduce a new keyword `class`, as its main effect is confusion about something that essential. I understand that back then it made sense to make it look "different", but I have seen this misunderstanding even on somewhat experienced programmers which is a little sad – 463035818_is_not_an_ai Sep 12 '22 at 13:00

0 Answers0