Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typedef structs declared inside class or outside?

Tags:

c++

visual-c++

I'm creating a class called ImageLoader that will be used to load various image formats. For various image formats there are certain structs used. For example with bmp files you have a BITMAPFILEHEADER struct and two others.

What I want to know is, when I'm putting my class definition in the header file, do I make the struct typedefs part of the class definition, or should they be separate, outside the class definition?

I'm not sure because if I was just declaring a struct variable, that would obviously happen in the class, but because I'm defining a type, I'm not sure if it's considered good design to define a type inside a class.

like image 782
Legion Avatar asked Apr 13 '12 16:04

Legion


1 Answers

My general rule is that if it will only be used in conjunction with that class, then declare it inside (it implies ownership); otherwise declare it separately.

like image 111
aldo Avatar answered Sep 29 '22 02:09

aldo