473,408 Members | 2,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

Expand|Select|Wrap|Line Numbers
  1. MList<MRvDispatcher *> *m_pDispatchers;
  2.           m_pDispatchers = new MList<MRvDispatcher *>();
  3.           MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
  4.           if (pSession)
  5.           {
  6. int threads = atoi(lau.getEnv("X_Y_ENQ_THREADS").c_str());
  7. for(int i=0; i<=threads;i++)
  8. {
  9. String session="RV"+i;
  10. MRvSession *pSession[i] = MRvSession::downCast(getComponentByName(session));
  11. MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession[i]);
  12. m_pDispatchers->push_back(pDispatcher);
Jan 13 '10 #1
5 1967
newb16
687 512MB
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.
Jan 13 '10 #2
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,

Expand|Select|Wrap|Line Numbers
  1. ** Functionality    : It performs the following operations
  2. **                        1. Accepts appXation properties from X_Y program
  3. **                        2. Checks for location (level1/MAN/WAN)
  4. **                        3. Starts the listener for corresponding location
  5. **--------------------------------------------------------------------------------------------
  6. */
  7.  
  8. #include <X_Y_Adapter.h>
  9. #include <X_level1_DataEventListener.h>
  10.  
  11.  
  12. X_Y_Adapter::X_Y_Adapter(MAppProperties* pMAppProperties)
  13.         :MApp(pMAppProperties) {}
  14.  
  15. //X_Y_Adapter::X_Y_Adapter(MAppProperties* pMAppProperties, MMessageBundle mb)
  16. //        :MApp(pMAppProperties)
  17. //{
  18. //    m_mb = mb;
  19. //}
  20.  
  21. X_Y_Adapter::~X_Y_Adapter()
  22. {
  23. }
  24.  
  25. void
  26. X_Y_Adapter::onInitialization() throw (MException)
  27. {
  28.     try
  29.     {
  30.         this->getTrace()->trace(MAPP_INFO_ROLE, " Adapter started successfully");
  31.         m_pMPublisher = MPublisher::downCast(getComponentByName("pub"));
  32.  
  33.         if (m_pMPublisher == 0) {
  34.             this->getTrace()->trace(MAPP_ERROR_ROLE, "Publisher object not found in the repository file");
  35.             throw MException( "onInitialization: Publisher not auto-created: pub");
  36.         }
  37.  
  38.         X_Adapter_Utils lau;
  39.         string loc = lau.getEnv("X_MW_LOCATION");
  40.         loc = lau.getUpper((char*)loc.c_str());
  41.         lau.checkLocation(loc);
  42.  
  43.           if (loc == "level1")
  44.         {
  45.             m_pMSubscriber = MSubscriber::downCast(getComponentByName("sub_level1"));
  46.             //get the subject of the sub "X.BCODE.*.ENQ.REQ" and replace the second
  47.             //part using the getenv(X_MW_level1_CODE) and set this subject to
  48.             //subscriber
  49.  
  50.             if (m_pMSubscriber == 0)
  51.             {
  52.                 this->getTrace()->trace(MAPP_ERROR_ROLE, "Subscriber object not found in the repository file");
  53.                 throw MException( "onInitialization: Subscriber not auto-created: sub");
  54.             }
  55.  
  56.             //Make the subscriber to accept both RV and AE formats
  57.             Mboolean bValidate = Mfalse;
  58.             m_pMSubscriber->validateMessage(bValidate);
  59.             //m_pMSubscriber->addListener(new X_level1_DataEventListener(m_pMPublisher, m_mb, this));
  60.             m_pMSubscriber->addListener(new X_level1_DataEventListener(m_pMPublisher, this));
  61.             this->getTrace()->trace(MAPP_INFO_ROLE, "level1 Adapter. Listening for messages from level1 and MAN");
  62.         }
  63.  
  64.  
  65.         MList<MRvDispatcher *> *m_pDispatchers;
  66.         m_pDispatchers = new MList<MRvDispatcher *>();
  67.         MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
  68.         if (pSession)
  69.         {
  70.                 //Get the # of threds to be spawned
  71.                     int threads = atoi(lau.getEnv("X_MW_ENQ_THREADS").c_str());
  72.             for(int i = 0; i <= threads; i++)
  73.             {
  74.                 // this->getTrace()->trace(MAPP_INFO_ROLE, "THREAD STARTED INSIDE DISPATCHER FOR LOOP");
  75.                 MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession);
  76.                 m_pDispatchers->push_back(pDispatcher);
  77.                 //delete (pDispatcher);
  78.             }
  79.         }
  80.     }
  81.     catch (MException me)
  82.     {
  83.         throw me;
  84.     }
  85.     catch (X_Exceptions le)
  86.     {
  87.         char str1[10];
  88.         int i = le.getLineno();
  89.         sprintf(str1,"%d",i);
  90.         string str = le.getDesc()+" at file "+le.getFilename()+" at line "+ str1;
  91.  
  92.         MString exception = (const char*) str.c_str();
  93.         throw MException(exception);
  94.     }
  95.  
  96. }
  97.  
  98. void
  99. X_Y_Adapter::onTermination() throw (MException)
  100. {
  101.     this->getTrace()->trace(MAPP_DEBUG_ROLE, "onTermination() is called");
  102. }
Jan 13 '10 #3
newb16
687 512MB
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.
Jan 13 '10 #4
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.

Expand|Select|Wrap|Line Numbers
  1. /*
  2. **--------------------------------------------------------------------------------------------
  3. ** Description        : This class starts the event listener threads for BRANCH
  4. ** @version        : 1.0
  5. ** Functionality    : It performs the following operations
  6. **                        1. Accepts appXation properties from X_Enquiry program
  7. **                        2. Checks for location (BRANCH)
  8. **                        3. Starts the listener for corresponding location
  9. **--------------------------------------------------------------------------------------------
  10. */
  11.  
  12. #include <X_Adapter.h>
  13. #include <X_Branch_DataEventListener.h>
  14.  
  15. X_Adapter::X_Adapter(MAppProperties* pMAppProperties)
  16.         :MApp(pMAppProperties) {}
  17.  
  18. //X_Adapter::X_Adapter(MAppProperties* pMAppProperties, MMessageBundle mb)
  19. //        :MApp(pMAppProperties)
  20. //{
  21. //    m_mb = mb;
  22. //}
  23.  
  24. X_Adapter::~X_Adapter()
  25. {
  26. }
  27.  
  28. void
  29. X_Adapter::onInitialization() throw (MException)
  30. {
  31.     try
  32.     {
  33.         this->getTrace()->trace(MAPP_INFO_ROLE, "Enquiry Adapter started successfully");
  34.         m_pMPublisher = MPublisher::downCast(getComponentByName("pub"));
  35.  
  36.         if (m_pMPublisher == 0) {
  37.             this->getTrace()->trace(MAPP_ERROR_ROLE, "Publisher object not found in the repository file");
  38.             throw MException( "onInitialization: Publisher not auto-created: pub");
  39.         }
  40.  
  41.         X_Adapter_Utils lau;
  42.         string loc = lau.getEnv("ABC_LOCATION");
  43.         loc = lau.getUpper((char*)loc.c_str());
  44.         lau.checkLocation(loc);
  45.  
  46.           if (loc == "BRANCH")
  47.         {
  48.             m_pMSubscriber = MSubscriber::downCast(getComponentByName("sub_BR"));
  49.             //get the subject of the sub "X.BCODE.*.ENQ.REQ" and replace the second
  50.             //part using the getenv(ABC_BRANCH_CODE) and set this subject to
  51.             //subscriber
  52.  
  53.             if (m_pMSubscriber == 0)
  54.             {
  55.                 this->getTrace()->trace(MAPP_ERROR_ROLE, "Subscriber object not found in the repository file");
  56.                 throw MException( "onInitialization: Subscriber not auto-created: sub");
  57.             }
  58.  
  59.             //Make the subscriber to accept both RV and AE formats
  60.             Mboolean bValidate = Mfalse;
  61.             m_pMSubscriber->validateMessage(bValidate);
  62.             //m_pMSubscriber->addListener(new X_Branch_DataEventListener(m_pMPublisher, m_mb, this));
  63.             m_pMSubscriber->addListener(new X_Branch_DataEventListener(m_pMPublisher, this));
  64.             this->getTrace()->trace(MAPP_INFO_ROLE, "Branch Adapter. Listening for messages from Branch ");
  65.         }
  66.  
  67. MList<MRvDispatcher *> *m_pDispatchers;
  68.           m_pDispatchers = new MList<MRvDispatcher *>();
  69.           MRvSession *pSession = MRvSession::downCast(getComponentByName("RV"));
  70.           if (pSession)
  71.           {
  72. int threads = atoi(lau.getEnv("ABC_ENQ_THREADS").c_str());
  73. for(int i=0; i<=threads;i++)
  74. {
  75. string session="RV"+i;
  76. MRvSession *pSession[i] = MRvSession::downCast(getComponentByName(session));
  77. MRvDispatcher *pDispatcher = new MRvDispatcher(this, pSession[i]);
  78. m_pDispatchers->push_back(pDispatcher);
  79. }
  80.         }
  81.     }
  82.     catch (MException me)
  83.     {
  84.         throw me;
  85.     }
  86.     catch (X_Exceptions le)
  87.     {
  88.         char str1[10];
  89.         int i = le.getLineno();
  90.         sprintf(str1,"%d",i);
  91.         string str = le.getDesc()+" at file "+le.getFilename()+" at line "+ str1;
  92.  
  93.         MString exception = (const char*) str.c_str();
  94.         throw MException(exception);
  95.     }
  96.  
  97. }
  98.  
  99. void
  100. X_Adapter::onTermination() throw (MException)
  101. {
  102.     this->getTrace()->trace(MAPP_DEBUG_ROLE, "onTermination() is called");
  103. }
Jan 14 '10 #5
newb16
687 512MB
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++.
Jan 14 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. It doesn't happen all the time but it does happen. When...
0
by: Jas Shultz | last post by:
I'm using Win2K3 Enterprise edition with the latest .NET framework installed. I have this problem with getting "out of disk space" errors. It doesn't happen all the time but it does happen. When...
3
by: Franko | last post by:
I get the following error. Ihave no idea why? Pl help Server Error in '/WebApplication1' Application. -------------------------------------------------------------------------------- Compilation...
0
by: z f | last post by:
i compile and test my vb.net asp.net web app. once in an hour or so i get a compilation error that only when i do IISRESET goes away. nothing related to my code. i compile and test on win XP...
0
by: Rod | last post by:
I've recently upgraded to Crystal Reports 11 Release 2 on my development machine. Right now I'm trying to get one of our ASP.NET 1.1 applications working with it. Several pages already work with...
1
by: sshankar | last post by:
Hi, New to Stored procedure. Basically just installed DB2 v8.1.0.36 Was trying to build a stored procedure.. It is giving following error.. Looks like some error related to configuration...
1
by: spitapps | last post by:
I want to have sessions on my website, this is my web.config file: <configuration> <appSettings/> <connectionStrings/> <system.web> <sessionState mode="InProc" cookieless="UseCookies"...
0
by: manicmax | last post by:
Hey I have a question for u I am taking connection string from IIS like this readonly string dataSource3 =ConfigurationManager.ConnectionStrings.ConnectionString; and using this dataSource3 ...
1
by: bhavanirayala | last post by:
Hello, I am using XML::Parsar in my perl file. but when I run the perl file, getting the following erro even I have the parser.pm and Dynaloader.pm files in the lib path. The error is: Can't...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.