Pages: [1]   Go Down
Author Topic: find error in Library: 'prefixString' was not declared in this scope (line 29)  (Read 759 times)
0 Members and 1 Guest are viewing this topic.
Freiburg
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi C/CPP Experts out there,

im all noob to C and C++ and seem to need some helpin hand , pointing there i made the Booboo or why the compiler is complaining. Im trying to build some library that may (or may not) help me with some automatic debugging or reporting messages. but that is not important here.

The Problem/Question is: What did i wrong? Why is the compiler saying that the variable "prefixString" is "not declared in this scope" even it IS declared in the header file as private AND its initialized in the constructor in the cpp file.

Is it some "String"-specific Problem here? or did i just do some stupid beginners mistake?

The ERROR Message is:

MyDebugTools.cpp:29: error: 'prefixString' was not declared in this scope

Thanks for any information pointing out what i did wrong here.

Here are my Files producing the Error:

MyDebugTools.h
Code:
/* MyDebugTools Class for Arduino 1.x by Axel Werner [mail@awerner.homeip.net]
 * free for non-commercial use.
 *
 * Version 2012-11-03 DEV/EXPERIMENTAL
 */


#ifndef MyDebugTools_h
#define MyDebugTools_h
 
#include <Arduino.h>


class MyDebugTools {

  private:
    unsigned int dispFreeRamIntervall; // 0 = disabled ; >0 in ms means do intervall
    unsigned long dispFreeRamLastCallMillis; // store last time (ms) when displayed.
    String prefixString;

    void dispFreeRamPrefix();
    int getFreeRam();
   
  public:
    MyDebugTools(); // constructor
    ~MyDebugTools(); // destructor

    void update();
    void setDispFreeRamIntervall(unsigned int intervall);
    void setDispFreeRamPrefixString(String s);
    void dispFreeRam();
};
#endif

MyDebugTools.cpp

Code:
/* MyDebugTools Class for Arduino 1.x by Axel Werner [mail@awerner.homeip.net]
 * free for non-commercial use.
 *
 * Version 2012-11-03 DEV/EXPERIMENTAL
 */


#include "MyDebugTools.h"

/*******************************************************************/
MyDebugTools::MyDebugTools(){
  dispFreeRamIntervall=0; // 0 = disabled ; >0 in ms means do intervall
  dispFreeRamLastCallMillis=millis();
  prefixString="";
}
//******************************************************************
MyDebugTools::~MyDebugTools(){
  /*nothing to destruct*/
}
//******************************************************************
void MyDebugTools::setDispFreeRamIntervall(unsigned int intervall){
  dispFreeRamIntervall=intervall; 
}   
//******************************************************************
void MyDebugTools::setDispFreeRamPrefixString(String s){
  prefixString=String(s); 
}   
//******************************************************************
void dispFreeRamPrefix() {
  if( prefixString.length() > 0 ){
    Serial.print( prefixString );
  }
}   
//******************************************************************
void MyDebugTools::dispFreeRam() {
  Serial.print(getFreeRam());
}   
//******************************************************************
void MyDebugTools::update(){ //non-blocking Timer-Interrupt/LOOP Service Routine
  if (dispFreeRamIntervall > 0){
    if( millis() - dispFreeRamLastCallMillis > dispFreeRamIntervall ){
      dispFreeRamPrefix();
      dispFreeRam();
      dispFreeRamLastCallMillis=millis();
    }
  }
}
//******************************************************************

/**************************************************
 * getFreeRam() - returns int, number of RAM bytes free/left
 **************************************************/
int getFreeRam() {
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

//******************************************************************
//******************************************************************

Arduino 1.01 skeleton
Code:
#include "MyDebugTools.h"

/**************************************************
 * GLOBAL VARIABLES + Constants
 **************************************************/
#define serialBaud 9600

MyDebugTools dt;

/**************************************************
 * setup()
 **************************************************/

void setup() {               
  Serial.begin(serialBaud);
  Serial.print(F("setup()...Serial active @ ")); Serial.println(serialBaud);
 
  dt.setDispFreeRamPrefixString("free Ram left:");
  dt.setDispFreeRamIntervall(3000);
}

/**************************************************
 * loop()
 **************************************************/

void loop() {
  Serial.println( F("loop()") );


 
  dt.update();
}


/**************************************************
 **************************************************/



Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Where is the compiler complaining about prefixString?
Code:
void dispFreeRamPrefix() {
  if( prefixString.length() > 0 ){
    Serial.print( prefixString );
  }
}
In some method that does not belong to the class.
Logged

Freiburg
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Where is the compiler complaining about prefixString?
In some method that does not belong to the class.

huh?!? dispFreeRamPrefix() is prototyped in the private section of the header file and its defined in the cpp file. So why doesnt it belong to the class??

sorry, but i dont get your point.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
dispFreeRamPrefix() is prototyped in the private section of the header file
Yes, it is.

Quote
its defined in the cpp file.
But, not the one prototyped in the header file.

The MyDebugTools:: part is missing.
Logged

Freiburg
Offline Offline
Newbie
*
Karma: 0
Posts: 11
Arduino rocks
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Quote
its defined in the cpp file.
But, not the one prototyped in the header file.

The MyDebugTools:: part is missing.

uhm... even if the method/function is supposed to be "private" ? uh... ok
for some reasons i thought only public methods would need that classname-prefix.

ok guess i need to re-read that stuff on how to make an library.
thanks.

greets,
Axel
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Every member of the class needs the class name and :: in front of the implementation of its methods. It's how the compiler knows that the function being implemented belongs to the class.
« Last Edit: November 03, 2012, 06:27:00 pm by PaulS » Logged

Pages: [1]   Go Up
Jump to: