Undeclared Identifier in class that is declared private?
Hey guys I have a class called validID. its broken up into validID.h and validID.cpp.
In validID.h I declare int id as private.
and in validID.cpp I try to set a value to id, but I get a compile error saying it is undeclared....
Here is my code, can you see what I'm doing wrong?
Thanks! :wave:
PHP Code:
//validID.h
#ifndef VALIDID_H
#define VALIDID_H
class validID {
public:
validID(int = 0); //default constructor
int getID() const; //return ID number
void setID(int); //set ID number
private:
int id; //id number
}; //end class validID
#endif
//-----------------------------------------------------------------
//validID.cpp
#include <iostream>
using std::cin;
using std::cout;
using std::endl;
#include "validID.h"
#include "errorHandler.h"
validID::validID(int idNum)
{
}// end constructor
void setID(int idNum)
{
if(idNum < 1 || idNum > 10000)
{
throw errorHandler();
}else{
id = idNum; //here is where the error is coming from
}// end if
}// end setID
Re: Undeclared Identifier in class that is declared private?
You missed the validID:: before the setID member function.
Re: Undeclared Identifier in class that is declared private?
That was it, thanks alot! :wave: