tem.ino: In constructor 'SensorReadings::SensorReadings(DHTReading, DHTReading, float)':
rack_cooling_system:57: error: no matching function for call to 'DHTReading::DHTReading()'
{ air1=a1;air2=a2;water=w;}
^
I may be wrong, but it looks like you're defining a function within the struct...sorta like one of those Russian Christmas boxes. I don't think you can do that.
econjack:
I may be wrong, but it looks like you're defining a function within the struct...sorta like one of those Russian Christmas boxes. I don't think you can do that.
A struct is just like a class, except the default access is public, rather than private.
Personally, if it involves code and data, I'd go for a class.
Again, I'm not accustomed to placing functions in a struct, constructor or otherwise. Given the protection a class can afford for encapsulation, what's the reason for using a struct? Placing any function in a struct is a C++ feature, so why not get the extra protection and use a class?
econjack:
Again, I'm not accustomed to placing functions in a struct, constructor or otherwise. Given the protection a class can afford for encapsulation, what's the reason for using a struct? Placing any function in a struct is a C++ feature, so why not get the extra protection and use a class?
A struct is EXACTLY the same thing as a class, with the one exception that the default access is public. Said another way, a class is nothing more than a struct, with the one excettion that the default access is private. There is absolutely NOTHING wrong with using a struct if you want all the members are public. In terms of "protection" they are identical, with the one exception above.
Regards,
Ray L.
RayLivingston:
A struct is EXACTLY the same thing as a class, with the one exception that the default access is public. Said another way, a class is nothing more than a struct, with the one excettion that the default access is private. There is absolutely NOTHING wrong with using a struct if you want all the members are public. In terms of "protection" they are identical, with the one exception above.
Regards,
Ray L.
I'm not trying to say anything is wrong with it, except to me I'd rather have everything default to private rather than public. That one exception is pretty important when it comes to data hiding/encapsulation.
econjack:
I'm not trying to say anything is wrong with it, except to me I'd rather have everything default to private rather than public. That one exception is pretty important when it comes to data hiding/encapsulation.
If your worried, you can just explicitly identify your class/struct members.
All I am trying to do is that I need to have an object called DHTReading which has two float attributes and SensorReadings which has two DHTReading objects along with a float object.
I am using those objects to return multiple values
The methods are just constructors for the objects so that I could do the following :
return DHTReading(val1, val2) ;
boshkash1151:
I am sorry I am lost. What is wrong with code?
You don't have the required default constructor, copy constructor or assignment operator for DHTReading that your struct needs. You should use references i.e.
Also, I would use a class and not a struct and then only make public those members that actually must be.
Edit: Checking the C++ specification it seems that the default constructor, copy constructor and assignment operator will be generated by the compiler if not explicitly declared so my analysis is wrong. This does not mean my solution to the problem is wrong.
econjack:
I'm not trying to say anything is wrong with it, except to me I'd rather have everything default to private rather than public. That one exception is pretty important when it comes to data hiding/encapsulation.
struct members can be given an access specifier of private, it's just not default (as already noted).
That being said, my (totally arbitrary) preference is to use a struct if the type conforms to the good 'ole C definition of a struct. Otherwise, use a class.