Go Down

Topic: Error with costructor without params (Read 436 times) previous topic - next topic

msx

Sep 08, 2008, 11:16 am Last Edit: Sep 08, 2008, 11:22 am by msx Reason: 1
This is probably a very stupid question but..
i have a class with two constructor, one takes one parameter, the other takes no parameters:

Code: [Select]

MD23::MD23(byte address)
{
 _address = address;
}

MD23::MD23()
{
 _address = DEF_ADDRESS;
}


Now, if i create the object like this:

Code: [Select]

MD23 md23(0x58);

It works perfectly, but if i write:
Code: [Select]

MD23 md23();


then whenever i call a method i have the following error:
error: request for member 'setMode' in 'md23', which is of non-class type 'MD23 ()()' In function 'void loop()':

I don't really get this error.. but i'm sure is something stupid :)
http://msx80.blogspot.com/

mellis

If you want to use the default constructor, don't put parentheses after the name of the variable.  That is, use:

MD23 md23;

not:

MD23 md23();

The latter actually creates a pointer to a function of no parameters that returns an MD23.

msx

http://msx80.blogspot.com/

Go Up