Pages: [1]   Go Down
Author Topic: Error with costructor without params  (Read 401 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
MD23::MD23(byte address)
{
  _address = address;
}

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

Now, if i create the object like this:

Code:
MD23 md23(0x58);
It works perfectly, but if i write:
Code:
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 smiley
« Last Edit: September 08, 2008, 04:22:52 am by msx » Logged


Forum Administrator
Cambridge, MA
Offline Offline
Faraday Member
*****
Karma: 11
Posts: 3538
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Full Member
***
Karma: 0
Posts: 113
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ah that explains all!
Thanks mellis smiley
Logged


Pages: [1]   Go Up
Jump to: