Getting compilation error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • atulpatil09
    New Member
    • Jan 2010
    • 3

    Getting compilation error

    when I am trying to compile the below code I am getting error as below,
    =============== =============== =============== ===
    Adapter.cpp:114 : error: âStringâ was not declared in this scope
    Adapter.cpp:114 : error: expected `;' before âsessionâ
    Adapter.cpp:115 : error: âsessionâ was not declared in this scope
    Adapter.cpp:115 : error: variable-sized object âpSessionâ may not be initialized
    =============== =============== ===============
    Could you please let me know how to solve the above compilation error for the below program snippet

    Code:
    MList<MRvDispatcher *> *m_pDispatchers;
              m_pDispatchers = new MList<MRvDispatcher *>();
              MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
              if (pSession)
              {
    int threads = atoi(lau.getEnv("X_Y_ENQ_THREADS").c_str());
    for(int i=0; i<=threads;i++)
    {
    String session="RV"+i;
    MRvSession *pSession[i] = MRvSession::downCast(getComponentByName(session));
    MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession[i]);
    m_pDispatchers->push_back(pDispatcher);
  • newb16
    Contributor
    • Jul 2008
    • 687

    #2
    What is String and where is it defined?
    Also, "RV"+i is undefined if 'threads' and then i is greater than 2.
    Then MRvSession *pSession[i] looks like declaration of variable-size array instead of assignment.

    Comment

    • atulpatil09
      New Member
      • Jan 2010
      • 3

      #3
      Still getting compilation error

      Thanks for the Reply,

      My program is as below,even if I do the suggested changes still it gives me the same error,kindly suggest,

      Code:
      ** Functionality	: It performs the following operations
      **                        1. Accepts appXation properties from X_Y program
      **                        2. Checks for location (level1/MAN/WAN)
      **                        3. Starts the listener for corresponding location
      **--------------------------------------------------------------------------------------------
      */
      
      #include <X_Y_Adapter.h>
      #include <X_level1_DataEventListener.h>
      
      
      X_Y_Adapter::X_Y_Adapter(MAppProperties* pMAppProperties)
      		:MApp(pMAppProperties) {}
      
      //X_Y_Adapter::X_Y_Adapter(MAppProperties* pMAppProperties, MMessageBundle mb)
      //		:MApp(pMAppProperties)
      //{
      //	m_mb = mb;
      //}
      
      X_Y_Adapter::~X_Y_Adapter()
      {
      }
      
      void
      X_Y_Adapter::onInitialization() throw (MException)
      {
      	try
      	{
      		this->getTrace()->trace(MAPP_INFO_ROLE, " Adapter started successfully");
      		m_pMPublisher = MPublisher::downCast(getComponentByName("pub"));
      
      		if (m_pMPublisher == 0) {
      			this->getTrace()->trace(MAPP_ERROR_ROLE, "Publisher object not found in the repository file");
      			throw MException( "onInitialization: Publisher not auto-created: pub");
      		}
      
      		X_Adapter_Utils lau;
      		string loc = lau.getEnv("X_MW_LOCATION");
      		loc = lau.getUpper((char*)loc.c_str());
      		lau.checkLocation(loc);
      
        		if (loc == "level1")
      		{
      			m_pMSubscriber = MSubscriber::downCast(getComponentByName("sub_level1"));
      			//get the subject of the sub "X.BCODE.*.ENQ.REQ" and replace the second
      			//part using the getenv(X_MW_level1_CODE) and set this subject to
      			//subscriber
      
      			if (m_pMSubscriber == 0)
      			{
      				this->getTrace()->trace(MAPP_ERROR_ROLE, "Subscriber object not found in the repository file");
      				throw MException( "onInitialization: Subscriber not auto-created: sub");
      			}
      
      			//Make the subscriber to accept both RV and AE formats
      			Mboolean bValidate = Mfalse;
      			m_pMSubscriber->validateMessage(bValidate);
      			//m_pMSubscriber->addListener(new X_level1_DataEventListener(m_pMPublisher, m_mb, this));
      			m_pMSubscriber->addListener(new X_level1_DataEventListener(m_pMPublisher, this));
      			this->getTrace()->trace(MAPP_INFO_ROLE, "level1 Adapter. Listening for messages from level1 and MAN");
      		}
      		
      
      		MList<MRvDispatcher *> *m_pDispatchers;
      		m_pDispatchers = new MList<MRvDispatcher *>();
      		MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
      		if (pSession)
      		{
      		        //Get the # of threds to be spawned
      	                int threads = atoi(lau.getEnv("X_MW_ENQ_THREADS").c_str());
      			for(int i = 0; i <= threads; i++)
      			{
      				// this->getTrace()->trace(MAPP_INFO_ROLE, "THREAD STARTED INSIDE DISPATCHER FOR LOOP");
      				MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession);
      				m_pDispatchers->push_back(pDispatcher);
      				//delete (pDispatcher);
      			}
      		}
      	}
      	catch (MException me)
      	{
      		throw me;
      	}
      	catch (X_Exceptions le)
      	{
      		char str1[10];
      		int i = le.getLineno();
      		sprintf(str1,"%d",i);
      		string str = le.getDesc()+" at file "+le.getFilename()+" at line "+ str1;
      
      		MString exception = (const char*) str.c_str();
      		throw MException(exception);
      	}
      
      }
      
      void
      X_Y_Adapter::onTermination() throw (MException)
      {
      	this->getTrace()->trace(MAPP_DEBUG_ROLE, "onTermination() is called");
      }

      Comment

      • newb16
        Contributor
        • Jul 2008
        • 687

        #4
        I haven't suggested any changes - I just asked what is 'String'. Now it can't give _the same_ error as now there is no 'String' with capital letter in the source code, and 'string' may require std:: namespace.

        Comment

        • atulpatil09
          New Member
          • Jan 2010
          • 3

          #5
          Hi This is true,you had not asked me to chnage anything,I was trying on my side,below is the actual code snippet that gives the compilation error,I followed error "declared in this scope" this is clear that before using string it needs to be declared,I tried it but it still gives error.can you please suggest.

          Code:
          /*
          **--------------------------------------------------------------------------------------------
          ** Description		: This class starts the event listener threads for BRANCH
          ** @version		: 1.0
          ** Functionality	: It performs the following operations
          **                        1. Accepts appXation properties from X_Enquiry program
          **                        2. Checks for location (BRANCH)
          **                        3. Starts the listener for corresponding location
          **--------------------------------------------------------------------------------------------
          */
          
          #include <X_Adapter.h>
          #include <X_Branch_DataEventListener.h>
          
          X_Adapter::X_Adapter(MAppProperties* pMAppProperties)
          		:MApp(pMAppProperties) {}
          
          //X_Adapter::X_Adapter(MAppProperties* pMAppProperties, MMessageBundle mb)
          //		:MApp(pMAppProperties)
          //{
          //	m_mb = mb;
          //}
          
          X_Adapter::~X_Adapter()
          {
          }
          
          void
          X_Adapter::onInitialization() throw (MException)
          {
          	try
          	{
          		this->getTrace()->trace(MAPP_INFO_ROLE, "Enquiry Adapter started successfully");
          		m_pMPublisher = MPublisher::downCast(getComponentByName("pub"));
          
          		if (m_pMPublisher == 0) {
          			this->getTrace()->trace(MAPP_ERROR_ROLE, "Publisher object not found in the repository file");
          			throw MException( "onInitialization: Publisher not auto-created: pub");
          		}
          
          		X_Adapter_Utils lau;
          		string loc = lau.getEnv("ABC_LOCATION");
          		loc = lau.getUpper((char*)loc.c_str());
          		lau.checkLocation(loc);
          
            		if (loc == "BRANCH")
          		{
          			m_pMSubscriber = MSubscriber::downCast(getComponentByName("sub_BR"));
          			//get the subject of the sub "X.BCODE.*.ENQ.REQ" and replace the second
          			//part using the getenv(ABC_BRANCH_CODE) and set this subject to
          			//subscriber
          
          			if (m_pMSubscriber == 0)
          			{
          				this->getTrace()->trace(MAPP_ERROR_ROLE, "Subscriber object not found in the repository file");
          				throw MException( "onInitialization: Subscriber not auto-created: sub");
          			}
          
          			//Make the subscriber to accept both RV and AE formats
          			Mboolean bValidate = Mfalse;
          			m_pMSubscriber->validateMessage(bValidate);
          			//m_pMSubscriber->addListener(new X_Branch_DataEventListener(m_pMPublisher, m_mb, this));
          			m_pMSubscriber->addListener(new X_Branch_DataEventListener(m_pMPublisher, this));
          			this->getTrace()->trace(MAPP_INFO_ROLE, "Branch Adapter. Listening for messages from Branch ");
          		}
          		
          MList<MRvDispatcher *> *m_pDispatchers;
                    m_pDispatchers = new MList<MRvDispatcher *>();
                    MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
                    if (pSession)
                    {
          int threads = atoi(lau.getEnv("ABC_ENQ_THREADS").c_str());
          for(int i=0; i<=threads;i++)
          {
          string session="RV"+i;
          MRvSession *pSession[i] = MRvSession::downCast(getComponentByName(session));
          MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession[i]);
          m_pDispatchers->push_back(pDispatcher);
          }
          		}
          	}
          	catch (MException me)
          	{
          		throw me;
          	}
          	catch (X_Exceptions le)
          	{
          		char str1[10];
          		int i = le.getLineno();
          		sprintf(str1,"%d",i);
          		string str = le.getDesc()+" at file "+le.getFilename()+" at line "+ str1;
          
          		MString exception = (const char*) str.c_str();
          		throw MException(exception);
          	}
          
          }
          
          void
          X_Adapter::onTermination() throw (MException)
          {
          	this->getTrace()->trace(MAPP_DEBUG_ROLE, "onTermination() is called");
          }

          Comment

          • newb16
            Contributor
            • Jul 2008
            • 687

            #6
            string is in <string> include file and std namespace, use it as std::string.
            "RV"+i construction with integer 'i' may have worked in java but not in c++.

            Comment

            Working...