Hey,
Im gettin this real weird error while compiling this file name ICalcState.cpp. The functions in this class require the class object Medl to be passed. But when I compile, I get an error saying,
ICalcState.h:12: `Modl' was not declared in this scope
for every locations where Modl is used, even after I included the Model header file. I rechecked the header name, and all other syntax. Im using gcc to compile and im also using a makefile. The Modl class compiles just fine, but this thing started after I created the ICalcState.
ICalcState is the only file throwing the error, and its located in the same dir as the rest of the classes.
Thanks a ton
raven
The files are as follows:
*********************************
Modl.h
#ifndef MODL_H
#define MODL_H
#include "NullOperation.h"
#include "NullCalcInterface.h"
#include "CalculatorEngine.h"
#include "ICalcState.h"
class Modl : public NullCalcInterface{
public:
NullOperation _pendingOperation;
NullOperation _currentOperation;
int _currentValue;
CalculatorEngine *_gui;
ICalcState _state;
// public:
Modl (CalculatorEngine *c);
int get_currentValue();
void set_currentValue(int value);
NullOperation get_currentOperation();
void set_currentOperation(NullOperation operation);
NullOperation get_pendingOperation();
void set_pendingOperation(NullOperation operation);
void set_error();
void set_state(NullCalcInterface s);
void clearKeyPressed();
void nonZeroDigitKeyPressed(int digit);
void zeroKeyPressed();
void plusKeyPressed();
void minusKeyPressed();
void timesKeyPressed();
void divideKeyPressed();
void equalsKeyPressed();
};
class someC {
public:
someC();
};
#endif
*********************************
Modl.cpp
#include "NullCalcInterface.h"
#include "Operations.h"
#include "NullOperation.h"
#include "CalculatorEngine.h"
//#include "ICalcState.h"
#include "Modl.h"
Modl::Modl(CalculatorEngine *c) {
_gui = c;
set_state(InitialState->Singleton);
}
int Modl::get_currentValue() {
return _currentValue;
}
void Modl::set_currentValue(int value){
_currentValue = value;
_gui->setDisplay(_currentValue);
}
NullOperation Modl::get_currentOperation() {
return _currentOperation;
}
void Modl::set_currentOperation(NullOperation operation) {
_currentOperation = operation;
}
NullOperation Modl::get_pendingOperation() {
return _pendingOperation;
}
void Modl::set_pendingOperation(NullOperation operation) {
_pendingOperation = operation;
}
void Modl::set_error(){
_gui->set_error();
}
void Model::set_state(NullCalcInterface s){
_state = s;
_state.activate(this);
}
void Modl::clearKeyPressed() {
_state.clearKeyPressed(this);
}
void Modl::nonZeroDigitKeyPressed(int digit){
_state.nonZeroDigitKeyPressed(this, digit);
}
void Modl::zeroKeyPressed() {
_state.zeroDigitKeyPressed(this);
}
void Modl:
lusKeyPressed() {
_state.plusKeyPressed(this);
}
void Modl::minusKeyPressed() {
_state.minusKeyPressed(this);
}
void Modl::timesKeyPressed() {
_state.timesKeyPressed(this);
}
void Modl::divideKeyPressed() {
_state.divideKeyPressed(this);
}
void Modl::equalsKeyPressed() {
_state.equalsKeyPressed(this);
}
someC::someC(){
}
***********************************
ICalcState.h
#ifndef ICALCSTATE_H
#define ICALCSTATE_H
#include "CalculatorEngine.h"
#include "Modl.h"
//extern class Model;
class ICalcState {
public:
ICalcState();
void activate(Modl c);
void nonZeroDigitKeyPressed(Modl mod, int digit);
void zeroDigitKeyPressed(Model mod);
void plusKeyPressed(Model mod);
void minusKeyPressed(Model mod);
void timesKeyPressed(Model mod);
void divideKeyPressed(Model mod);
void equalsKeyPressed(Model mod);
void clearKeyPressed(Model mod);
};
#endif
**********************************
ICalcState.cpp
#include "Modl.h"
#include "ICalcState.h"
ICalcState::ICalcState(){
}
void ICalcState::activate(Modl l) {
}
void ICalcState::nonZeroDigitKeyPressed(Modl model, int digit) {
}
void ICalcState::zeroDigitKeyPressed(Model model) {
}
void ICalcState:
lusKeyPressed(Model model) {
}
void ICalcState::minusKeyPressed(Model model) {
}
void ICalcState::timesKeyPressed(Model model) {
}
void ICalcState::divideKeyPressed(Model model) {
}
void ICalcState::equalsKeyPressed(Model model) {
}
void ICalcState::clearKeyPressed(Model model) {
}
********************************
Makefile
CONFIG=/projects/CSE250/C++/include/MakeConfiguration
include $(CONFIG)
# These variables determine where variable files are located.
Bin = .
oDir = .
sDir = .
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
# This variable determines the name of the executable to be produced.
PROG= $(Bin)/Calculator
EXOBJS= $(oDir)/CalculatorEngine.o $(oDir)/Addition.o $(oDir)/State.o $(oDir)/Subtraction.o $(oDir)/Multiplication.o $(oDir)/Division.o $(oDir)/Operations.o $(oDir)/NullOperation.o $(oDir)/Modl.o $(oDir)/NullCalcInterface.o $(oDir)/ICalcState.o
CLEANEXTS= $(PROG) $(EXOBJS)
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
.PHONY: default all objs clean cleanobj cleanall
default: all
all: $(PROG)
objs: $(EXOBJS)
# Note that this rule has no dependencies listed; it still requires two lines!
# See the explanation of rule structure below.
clean:
-rm -f $(CLEANEXTS); rm -f *~ \#*
#
# EXPLANATION OF HOW TO MAKE THE ZIP FILE TO SUBMIT
#
# This will clean and then make then make a submission-ready zip file.
# Note that it is assumed that the current directory is named 'PP1'.
# To create the zip file to submit, type 'gmake submitZip' in the
# current directory (which should be named PP1).
submitZip: clean
( cd ..; rm PP1.zip ; zip -r PP1.zip PP1 )
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
$(PROG): $(EXOBJS)
$(CXX) -o $@ $(EXOBJS) $(OBJS) $(LDFLAGS)
$(oDir)/CalculatorEngine.o: $(sDir)/CalculatorEngine.cpp $(sDir)/CalculatorEngine.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/State.o: $(sDir)/State.cpp $(sDir)/State.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Addition.o: $(sDir)/Addition.cpp $(sDir)/Addition.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Subtraction.o: $(sDir)/Subtraction.cpp $(sDir)/Subtraction.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Multiplication.o: $(sDir)/Multiplication.cpp $(sDir)/Multiplication.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Division.o: $(sDir)/Division.cpp $(oDir)/Division.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Operations.o: $(sDir)/Operations.cpp $(oDir)/Operations.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/NullOperation.o: $(sDir)/NullOperation.cpp $(oDir)/NullOperation.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/Modl.o: $(sDir)/Modl.cpp $(oDir)/Modl.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/NullCalcInterface.o: $(sDir)/NullCalcInterface.cpp $(oDir)/NullCalcInterface.h
$(CXX) -c $(CFLAGS) -o $@ $<
$(oDir)/ICalcState.o: $(sDir)/ICalcState.cpp $(oDir)/ICalcState.h
$(CXX) -c $(CFLAGS) -o $@ $<