Go Down

Topic: find error in Library: 'prefixString' was not declared in this scope (line 29) (Read 875 times) previous topic - next topic

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: [Select]

/* 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: [Select]

/* 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: [Select]

#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();
}


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





PaulS

Where is the compiler complaining about prefixString?
Code: [Select]
void dispFreeRamPrefix() {
  if( prefixString.length() > 0 ){
    Serial.print( prefixString );
  }
}

In some method that does not belong to the class.


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.

PaulS

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.

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

PaulS

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.

Go Up