Thread: State design pattern - can't find an error

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2016
    Posts
    36

    Post State design pattern - can't find an error

    Hello guys, I am trying to implement a State Design pattern, but I am stuck with it since I can't get my code compiled, and can't find solution to it

    Error happens in this part of the code, while trying to call method setState
    Code:
    void StartTransmitted::nextState(I2CStateContext* currentContext)
    {
        cout << "Start Transmitted is running .." << endl;
        this->sendSignal();
        // this is where error occours
        currentContext->setState(new AdrWTransACKRec());
    }



    StartTransmitted.h
    Code:
    #pragma once
    #ifndef _START_TRANSMITTED_H_
    #define _START_TRANSMITTED_H_
    
    #include "I2CState.h"
    
    class StartTransmitted : public I2CState
    {
        public:
            void nextState(I2CStateContext* currentContext);
    
        private:
            void sendSignal(void);
    };
    
    #endif


    StartTransmitted.cpp
    Code:
    #include "StartTransmitted.h"
    #include "AdrWTransACKRec.h"
    
    
    void StartTransmitted::nextState(I2CStateContext* currentContext)
    {
        cout << "Start Transmitted is running .." << endl;
        this->sendSignal();
        // This is line where error happens
        currentContext->setState(new AdrWTransACKRec());
    
    }
    
    void StartTransmitted::sendSignal(void)
    {
        cout << "Sending start signal" << endl;
    }
    I2CState.h
    Code:
    #pragma once
    #ifndef _I2C_STATE_H_
    #define _I2C_STATE_H_
    
    #include <iostream>
    
    class I2CStateContext;
    
    using namespace std;
    
    class I2CState
    {
        public:
            virtual void nextState(I2CStateContext* currentContext);
    
        public:
            virtual void sendSignal(void);
            
    };
    
    #endif
    I2CStateContext.h
    Code:
    #include "I2CStateContext.h"
    
    I2CStateContext::I2CStateContext()
    {
        //this->currentState = new State();
    }
    
    void I2CStateContext::setState(I2CState* newState)
    {
        this->currentState = newState;
    }
    
    void I2CStateContext::nextState()
    {
        currentState->nextState(this);
    }
    I2CStateContext.cpp
    Code:
    #pragma once
    #ifndef _I2C_CONTEXT_H_
    #define _I2C_CONTEXT_H_
    
    #include "I2CState.h"
    
    class I2CStateContext
    {
        private:
            I2CState* currentState;
        
        public:
            I2CStateContext();
            void setState(I2CState* newState);
            void nextState();
    
    };
    
    #endif
    Attached Images Attached Images State design pattern - can't find an error-error-jpg 
    Last edited by ZeroesAndOnes; 03-26-2017 at 02:22 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. design pattern for information manager?
    By patiobarbecue in forum C++ Programming
    Replies: 5
    Last Post: 12-08-2009, 08:13 PM
  2. What design pattern to use here?
    By h3ro in forum C++ Programming
    Replies: 1
    Last Post: 04-15-2009, 06:41 PM
  3. Replies: 7
    Last Post: 09-13-2008, 07:00 PM
  4. Virtual function design pattern
    By George2 in forum C++ Programming
    Replies: 6
    Last Post: 03-19-2008, 07:18 AM
  5. what would be an appropriate design pattern?
    By Raven Arkadon in forum C++ Programming
    Replies: 2
    Last Post: 07-14-2006, 07:14 AM

Tags for this Thread