Go Down

Topic: How do I debug a new class in arduino IDE (Read 404 times) previous topic - next topic


Feb 10, 2012, 02:21 am Last Edit: Feb 10, 2012, 02:38 am by Coding Badly Reason: 1
I've decided that I want to create some classes to make my life easier. The first one that I wanted to create was  a "Line". I get an error message and want to figure out how i can debug this?, this is my code:

Code: [Select]
#include <Line.h>

Line line();

void setup() {
 // put your setup code here, to run once:
 line.set(1, 2, 3, 4);

void loop() {
 // put your main code here, to run repeatedly:

This is my error message:
ColourSphereCode.cpp: In function 'void setup()':
ColourSphereCode:6: error: request for member 'set' in 'line', which is of non-class type 'Line ()()'
ColourSphereCode.cpp: In function 'void loop()':
ColourSphereCode:11: error: request for member 'm' in 'line', which is of non-class type 'Line ()()'

And this is my Line.h:
#ifndef Line_h
#define Line_h

#include "Arduino.h"

class Line
   void set(double x1,double  y1,double  x2,double y2);
 double m();
 double c();
 double _x1;
 double _y1;
 double _x2;
 double _y2;


and this is my Line.cpp:

#include "Arduino.h"
#include "Line.h"


// define the two end points of the line
void Line::set(double x1, double y1, double x2, double y2)
 _x1 = x1;
 _y1 = y1;
 _x2 = x2;
 _y2 = y2;

// return the slope of the line
double m()
 return 1.1;

// return the offset of the line
double c()
 return 2.3;

so it would be great if someone can see where I'm going wrong but it would be even better if there is an 'easy" way that I can learn how to debug these errors and work with developing classes. The morse example looks  a little thin on the ground for this, but maybe there is another place that I can look?

Moderator edit: [code] [/code] tags added.


Code: [Select]
Line line();

This declares a function, taking no arguments, called "line," returning a Line.
You want to declare a global variable initialized by the default (no-argument) constructor:

Code: [Select]
Line line;

And, yes, I've done C++ since version 1 (25 years ago? something like that) and this *still* bites me once in a while...

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131