Go Down

Topic: I don't seem to understand C++ (Read 549 times) previous topic - next topic

RCork

Jan 13, 2013, 10:52 am Last Edit: Jan 13, 2013, 08:34 pm by RCork Reason: 1
c++ stuff

I program in c and I cannot find any help with this problem in the C++ searches I have done.
I am accessing several DHT11 packages.  I am using the dht11 lib which seems to be written in C++

I am trying to use a function to process the serial data received from each of the packages.

my problem is I am trying to use a pointer to each package's data.
proper includes
Code: [Select]

#include <dht11.h>

I declared the objects

Code: [Select]
dht11 DHT11one;
dht11 DHT11two;


//then within the loop I will call each one and send it to:

Code: [Select]
void loop
{
 int chk1 = DHT11one.read(DHTPIN1);
 int chk2 = DHT11two.read(DHTPIN2);
 doTemp( &DHT11one);
 doTemp( &DHT11two);
}


void doTemp(dht11 *DHT11chk)
{
 float aTemp = *DHT11chk.temperature;
 do other stuff ... (store the temperature in a array, calc the average and send it to a display)
}


I guess I do not understand C++ but this does not work.  it tells me that DHT11chk is not declared within this scope

any and all help is appreciated!


Moderator edit: [code] [/code] tags added.
Author edit: clarify some information and correct a typo.

Coding Badly

Quote
proper includes


What does that mean?

marco_c

Even in C the parameter passed as a pointer would be declared as type *varname, not &varname.
Arduino libraries http://arduinocode.codeplex.com
Parola hardware & library http://parola.codeplex.com

robtillaart

Try to get a copy of Kerningham and Ritchie C 2nd edition to learn some basics about C pointers

also a good learner = http://www.cplusplus.com/reference/cctype/
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Chaul

This is where you create an instance of the class.
dht11 DHT11one;

This could do without the &-symbol, if you have defined the function to take a reference to the instance in.
doTemp( &DHT11one);

But, if it says dht11 has not been declared, you must not have included a header before you created the instance in the first place. And the type name is case-sensitive.

The pointer symbol here looks a little weird, but it does depend on what the temperature is returned as from the library. I assume it's a float anyways, and I think it would work better without the pointer symbol for what you are trying to do with it.
float aTemp = *DHT11.temperature;

Go Up