Compile error - var not declared in this scope

Hi,

I have a maddening compile error which I have already spent too much time on. Can someone please help?

The message is:

Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Mega or Mega 2560, ATmega2560 (Mega 2560)"

D:DDocumentsArduino SketcheslibrariesAClockAClock.cpp: In function 'void setOnce(boolean)':
D:DDocumentsArduino SketcheslibrariesAClockAClock.cpp:11:3: error: 'once' was not declared in this scope
   once = flip;    // "once was not declared in this scope" ! ...but once is private in this class"
   ^

...and here is the code... just the juicy bits...

My sketch (in D:DDocumentsArduino SketchesATestclock)

#include <AClock.h>  

AClock clock;  // Instantiate.

void setup()
{
  clock.setOnce(false);
}

void loop()
{
}

ACLock.h (in D:DDocumentsArduino SketcheslibrariesAClock)

#include <arduino.h>

#ifndef AClock_h
#define AClock_h

class AClock{

public:
void setOnce(boolean flip){
// Set flag so we can do things once.
}

boolean getOnce(){
// Get the once flag value
}

private:
boolean once;
};  // End class Clock 
#endif

AClock.cpp (same folder as AClock.h)

#if defined(ARDUINO) && ARDUINO >= 100
 #include "Arduino.h"
#else
 #include "WProgram.h"
#endif

#include <AClock.h> 

void setOnce(boolean flip){
// Set flag so we can do things once.
  once = flip;    // "once was not declared in this scope" ! ...but once is private in this class"
}

boolean getOnce(){
// Get the once flag value
  return once;
}

Thanks in advance...

Main error (fixed version):

void AClock::setOnce(boolean flip){
// Set flag so we can do things once.
  once = flip;
}

boolean AClock::getOnce(){
// Get the once flag value
  return once;
}

Fixing this will probably show the next error:

class AClock{

public:
void setOnce(boolean flip){
// Set flag so we can do things once.
}

boolean getOnce(){
// Get the once flag value
}

private:
boolean once;
};

I think this should be (fixed version):

class AClock{

public:
void setOnce(boolean flip);
boolean getOnce();

private:
boolean once;
};

Thanks Whandall that looks like it fixed the code. It got to "Done uploading."

But then a lot of error messages like "avrdude: stk500v2_ReceiveMessage(): timeout. No doubt something to do with my recent upgrade to IDE 1.6.5.

Any ideas are welcome...

Any ideas are welcome...

Check the port you are using, check the USB connection, revert to an earlier version of the IDE.

Thanks HeliBob all sorted now...

Just to summarise:
Initial problem caused by two coding errors.

  1. The AClock.h file had:
    type methodName(){}
    it needed
    type methodName();

  2. The AClock.cpp file had:
    void setOnce(boolean flip){
    it needed
    void AClock::setOnce(boolean flip){

Final problem was wrong port.

So now you know how to define and declare (basic) classes?

You have to tell the compiler somehow that the function is a member function.

C++ just happens to pick the Class::method() syntax.

I get same error with the same file in both win 7-1 and Linux Ubuntu 14.04 and it is supposed to be for the Geetech I3 Pro C Dual Extruder 3D Printer with GT2560 Version A

Temperature.cpp: In function “Void manage_heater()'s
Temperature.cpp:665:1 error unable to find a register to spill in class 'POINTER_REGS'
}
^
temperature.cpp: 665:1 error : this is insn:
(isn 95 94 97 4 ( set (reg/v:SF 103 [ pid_input ]
( mem: SF (post_inc:HI 146 [ ivtmp.209v] ) ) [4 MEM [base:_110.
Offset: 0B]+0 S4 A8] ) ) temperature.cpp:449 99 {*movsf}
(expr_list : REG_INC (reg : HI 146 [ivtmp.209 ] )
(nil) ) )
temperature.cpp:665 confused by earlier errors, bailing out

that is what I get . . I have no ideal as to how to fix it as I got the files already editied and for my 3D printer

Temperature.cpp: In function "Void manage_heater()'s

I am absolutely certain that that is NOT what the error message says. Is it really so hard to copy and paste the EXACT text output by the compiler?

it is supposed to be for the Geetech I3 Pro C Dual Extruder 3D Printer with GT2560 Version A

Which isn't an Arduino. Perhaps you'd get more help at http://www.ford.com.