hello all ,
i have my idl defined as follows :

#ifndef schedule_Mgmt_idl
#define schedule_Mgmt_idl
 
module schedule_Mgmt
{
   
   //*************************** Structures *******************************
 
   struct planData {
                      string planName;
                      string planDescription;
                      string scriptExec;
                      string startDate;
                      string startTime;
                      string stopDate;
                      string stopTime;
                      string delayInt;
                      boolean repeatDelay;
                      boolean notOnWeekend;
                      boolean validity;
                      string tempTime;
                      string tempDate;    
                   };
 

   typedef sequence <planData> planList;
 
   //****************************** Exceptions *****************************
 
   exception alreadyExists         {string reason;};
   exception unknownErr            {string reason;};
   exception doNotExist            {string reason;};
   exception communicationFailure  {string reason;};
   exception processingFailure     {string reason;};
 
   //****************************** Interfaces *****************************
 
   interface config
   {
 
        planList getPlandata() raises (doNotExist,unknownErr);
 
        boolean createPlan(in planData newPlanData)
                           raises (alreadyExists, unknownErr);
 
        boolean modifyPlan(in string schedPlanName,
                           in planData modifyPlanData)
                           raises (unknownErr);
 
        boolean removePlan(in string schedPlanName)
                           raises (unknownErr);
                  
        boolean activatePlan(in string schedPlanName)
                             raises (unknownErr);
                    
        boolean deactivatePlan(in string schedPlanName)
                               raises (unknownErr);
    };
 
    interface Listener
    {
        void message(in string msg);
    };
 
    interface MessageServer
    {
        void register(in Listener lt);
        void unregister(in string lt);
  
    };
 
};
   
#endif

and my getPlanData.cpp file as follows :

#include <getPlanData.h>
#include <writeLog.h>

schedule_Mgmt::planList getPlanData()
{
  try
  {
     
     LogItf::setProcessName("Schedule_Mgmt");
     schedule_Mgmt::planList singleIMEIarr1;

     // Initialise Session using Session Pool
     Session::initSessionPool("BOSS", "E_SESSION_EIR", 2,  false, true);

     // Acquire session while initializing the Session.
     Session * schedSession1 ;
     schedSession1 = new  Session();

     DbSchedule * objschedule ;
        
     objschedule = new DbSchedule(schedSession1, "Schedule_mgmt");
    
     objschedule->StartTransaction(10);
     
     objschedule->GetTableDescription();
    
 
      struct singleIMEI 
     {
      
         string planName;
         string planDescription;
         string scriptExec;
         string startDate;
         string startTime;
         string stopDate;
         string stopTime;
         string delayInterval;
         bool repeatDelay;
         bool notOnWeekend;
         bool activate;
         string tempTime;
         string tempDate;    
     }  singleIMEIarr[1000];  //VECTOR IMPLEMENTATION PENDING
     
    
      int j = 1;
      objschedule->StartFetch();
      do
      {
          
          for (int i=1; (i <= objschedule->GetMaxColumns()); i++)
          {
               //cout << endl <<"venkat" << endl;
               //cout << objschedule->GetColumnName(i) << " = " << objschedule->GetColumnValue(i) << ", " ;
               
               if (i == 1)
               {
                    singleIMEIarr[j].planName=objschedule->GetColumnValue(i);
               }
               else if (i == 2)
               {    
                    singleIMEIarr[j].planDescription=objschedule->GetColumnValue(i);
               }                   
               else if (i == 3)
               {    
                    singleIMEIarr[j].scriptExec=objschedule->GetColumnValue(i);
               }
               else if (i == 4)
               {    
                    singleIMEIarr[j].startDate=objschedule->GetColumnValue(i);
               }
               else if (i == 5)
               {    
                    singleIMEIarr[j].startTime=objschedule->GetColumnValue(i);
               }
               else if (i == 6)
               {    
                    singleIMEIarr[j].stopDate=objschedule->GetColumnValue(i);
               }
               else if (i == 7)
               {    
                    singleIMEIarr[j].stopTime=objschedule->GetColumnValue(i);
               }
               else if (i == 8)
               {    
                    singleIMEIarr[j].delayInterval=objschedule->GetColumnValue(i);
               }
               else if (i == 9)
               {    
                    bool output_repeat;
                    string repeat_val = objschedule->GetColumnValue(i);
                    if (strcmp (repeat_val.c_str(),"1") == 0)
                    {
                      output_repeat = true;
                    }
                    else
                    {
                      output_repeat = false;
                    }
                    singleIMEIarr[j].repeatDelay= output_repeat;
               }
               else if (i == 10)
               {    
                    bool output_notOnWeekend;
                    string notOnWeekend_val = objschedule->GetColumnValue(i);
                    if (strcmp (notOnWeekend_val.c_str(),"1") == 0)
                    {
                      output_notOnWeekend = true;
                    }
                    else
                    {
                      output_notOnWeekend = false;
                    }
                    singleIMEIarr[j].notOnWeekend= output_notOnWeekend;

               }
               else if (i == 11)
               {
                    bool output_activate;
                    string activate_val = objschedule->GetColumnValue(i);
                    if (strcmp (activate_val.c_str(),"1") == 0)
                    {
                      output_activate = true;
                    }
                    else
                    {
                      output_activate = false;
                    }
                    singleIMEIarr[j].activate= output_activate;

               }

               else if (i == 12)
               {    
                    singleIMEIarr[j].tempTime=objschedule->GetColumnValue(i);
               }
               else if (i == 13)
               {    
                    singleIMEIarr[j].tempDate=objschedule->GetColumnValue(i);
               }     
            }
          cout << singleIMEIarr[j].planName << "," << singleIMEIarr[j].planDescription << "," << singleIMEIarr[j].scriptExec << "," << singleIMEIarr[j].startDate << "," << singleIMEIarr[j].startTime << "," << singleIMEIarr[j].stopDate << "," << singleIMEIarr[j].stopTime << "," << singleIMEIarr[j].delayInterval << "," << singleIMEIarr[j].repeatDelay << "," << singleIMEIarr[j].notOnWeekend << "," << singleIMEIarr[j].activate << "," << singleIMEIarr[j].tempTime << "," << singleIMEIarr[j].tempDate;
          j = j + 1;  
          cout << endl ;
      } while (objschedule->FetchNextTuple() == true) ;
     
 
     cout << "PLANNAME,PLANDESCRIPTION,SCRIPTEXEC,STARTDATE,STARTIME,STOPDATE,STOPTIME,REPEATDELAY,NOTONWEEKEND,ACTIVATE" <<  "\n";
     
     for (int k=1; k <= 5; k++)
     {
         cout << singleIMEIarr[k].planName << "," << singleIMEIarr[k].planDescription << "," << singleIMEIarr[k].scriptExec << "," << singleIMEIarr[k].startDate << "," << singleIMEIarr[k].startTime << "," << singleIMEIarr[k].stopDate << "," << singleIMEIarr[k].stopTime << "," << singleIMEIarr[k].delayInterval << singleIMEIarr[k].repeatDelay << "," << singleIMEIarr[k].notOnWeekend << "," << singleIMEIarr[k].activate << "," << singleIMEIarr[k].tempTime << "," << singleIMEIarr[k].tempDate << "\n";
     }
 
     // delete schedSession1 ;
     
     // Deletes Session using Session Pool
     SessionPool::deletePool();
     
     return singleIMEIarr[1000];
     
     char info[50] = "PLAN DISPLAYED";
     writeLog(NULL,info);
     
  }
  catch(...)
  {
     char error[50] = "PLAN CANNOT BE DISPLAYED";
     writeLog(NULL,error);
     cout<<"Unknown Error";
     throw;
  }       
}

i get the following error :
Error 339: "getPlanData.cpp", line 180 # Return type 'struct singleIMEI' does
not match expected return type 'class planList'
return singleIMEIarr[1000];
^^^^^^^^^^^^^^^^^^^
i need to return the singleIMEIarr with the return type "planList",
i have tried type casting , but nothing seems to work ,
any suggestions would be of great help
thank you

Recommended Answers

All 10 Replies

Your compiler is correct. If you want that function to return something else then change the return type on line 5 of the *.cpp file, and also in the class declaration. Functions can not return arrays like you are trying to do in line 162 of the code you posted.

Other problems:
line 162. that is a return line. The code following it will never get executed.

thank you , but is there no way of converting (type casting) it to the class type ?

>>return singleIMEIarr[1000];

That line is illegal.

>>but is there no way of converting (type casting) it to the class type ?
Why didn't you just use schedule_Mgmt::plainData structure instead of creating yet another structure with identical contents (starting on line 29 of *.cpp file)?

im trying get all the data from oracle database , store it in an array of structures and return the contents of the array.

>>Why didn't you just use schedule_Mgmt::plainData structure instead of creating yet another structure with identical contents (starting on line 29 of *.cpp file)?
i havent tried it , will give it a shot , is there any other workaround for this problem that u can think of ?

Make it a pointer

schedule_Mgmt::plainData* singleIMEIarr = new schedule_Mgmt::plainData[1000];

...
...
return singleIMEIarr;

And don't forget to delete[] that pointer in the receiving function.

Another alternative is to make it a vector passed in by reference so that getPlanData() can populate the vector

void  getPlanData(vector<schedule_Mgmt::planList>& list)
{
     

}

im using HP-UX .vector implementation isnt possible coz a header file <stdin.h> (or <stdint.h> not sure ) is not available. for some reason hp did not include it. thats y im trying to use array of structures.
>>schedule_Mgmt::planData* singleIMEIarr = new schedule_Mgmt::planData[1000];
it aint working
the function is of planList type (sequence defined in the corba idl)
i need to return the array in "planList" type,

Oh I see planList is a typedef. Well then just replace it

planList* singleIMEIarr = new planList[1000];

...
...
return singleIMEIarr;

im using HP-UX .vector implementation isnt possible coz a header file <stdin.h> (or <stdint.h> not sure ) is not available.,

vector is not declared in either of those header files. Its in <vector> header file, which will be supplied by every c++ compiler in the world except maybe some embedded compilers. So I think you need to search your compiler's include directory and I'll bet my boots it will contain a header file named vector (and without a .h extension)

#include <vector>
// other c++ code here

>>planList* singleIMEIarr = new planList[1000];


thank you . thanks a ton man , that worked :)

oops im sorry , i actually made that change in getPlanData.cpp and compiled another .cpp file with the same name in another path.

>>planList* singleIMEIarr = new planList[1000];
it did not work

#include <getPlanData.h>
#include <writeLog.h>

schedule_Mgmt::planList getPlanData()
{
  try
  {
     
     LogItf::setProcessName("Schedule_Mgmt");
     //schedule_Mgmt::planList singleIMEIarr1;

     // Initialise Session using Session Pool
     Session::initSessionPool("BOSS", "E_SESSION_EIR", 2,  false, true);

     // Acquire session while initializing the Session.
     Session * schedSession1 ;
     schedSession1 = new  Session();

     DbSchedule * objschedule ;
        
     objschedule = new DbSchedule(schedSession1, "Schedule_mgmt");
    
     objschedule->StartTransaction(10);
     
     objschedule->GetTableDescription();
    
 
      schedule_Mgmt::planList singleIMEI 
     {
      
         string planName;
         string planDescription;
         string scriptExec;
         string startDate;
         string startTime;
         string stopDate;
         string stopTime;
         string delayInterval;
         bool repeatDelay;
         bool notOnWeekend;
         bool activate;
         string tempTime;
         string tempDate;    
     };
     schedule_Mgmt::planList* singleIMEIarr = new schedule_Mgmt::planList[1000];
  //VECTOR IMPLEMENTATION PENDING
     
    
      int j = 1;
      objschedule->StartFetch();
      do
      {
          
          for (int i=1; (i <= objschedule->GetMaxColumns()); i++)
          {
               //cout << endl <<"venkat" << endl;
               //cout << objschedule->GetColumnName(i) << " = " << objschedule->GetColumnValue(i) << ", " ;
               
               if (i == 1)
               {
                    singleIMEIarr[j].planName=objschedule->GetColumnValue(i);
               }
               else if (i == 2)
               {    
                    singleIMEIarr[j].planDescription=objschedule->GetColumnValue(i);
               }                   
               else if (i == 3)
               {    
                    singleIMEIarr[j].scriptExec=objschedule->GetColumnValue(i);
               }
               else if (i == 4)
               {    
                    singleIMEIarr[j].startDate=objschedule->GetColumnValue(i);
               }
               else if (i == 5)
               {    
                    singleIMEIarr[j].startTime=objschedule->GetColumnValue(i);
               }
               else if (i == 6)
               {    
                    singleIMEIarr[j].stopDate=objschedule->GetColumnValue(i);
               }
               else if (i == 7)
               {    
                    singleIMEIarr[j].stopTime=objschedule->GetColumnValue(i);
               }
               else if (i == 8)
               {    
                    singleIMEIarr[j].delayInterval=objschedule->GetColumnValue(i);
               }
               else if (i == 9)
               {    
                    bool output_repeat;
                    string repeat_val = objschedule->GetColumnValue(i);
                    if (strcmp (repeat_val.c_str(),"1") == 0)
                    {
                      output_repeat = true;
                    }
                    else
                    {
                      output_repeat = false;
                    }
                    singleIMEIarr[j].repeatDelay= output_repeat;
               }
               else if (i == 10)
               {    
                    bool output_notOnWeekend;
                    string notOnWeekend_val = objschedule->GetColumnValue(i);
                    if (strcmp (notOnWeekend_val.c_str(),"1") == 0)
                    {
                      output_notOnWeekend = true;
                    }
                    else
                    {
                      output_notOnWeekend = false;
                    }
                    singleIMEIarr[j].notOnWeekend= output_notOnWeekend;

               }
               else if (i == 11)
               {
                    bool output_activate;
                    string activate_val = objschedule->GetColumnValue(i);
                    if (strcmp (activate_val.c_str(),"1") == 0)
                    {
                      output_activate = true;
                    }
                    else
                    {
                      output_activate = false;
                    }
                    singleIMEIarr[j].activate= output_activate;

               }

               else if (i == 12)
               {    
                    singleIMEIarr[j].tempTime=objschedule->GetColumnValue(i);
               }
               else if (i == 13)
               {    
                    singleIMEIarr[j].tempDate=objschedule->GetColumnValue(i);
               }     
            }
          cout << singleIMEIarr[j].planName << "," << singleIMEIarr[j].planDescription << "," << singleIMEIarr[j].scriptExec << "," << singleIMEIarr[j].startDate << "," << singleIMEIarr[j].startTime << "," << singleIMEIarr[j].stopDate << "," << singleIMEIarr[j].stopTime << "," << singleIMEIarr[j].delayInterval << "," << singleIMEIarr[j].repeatDelay << "," << singleIMEIarr[j].notOnWeekend << "," << singleIMEIarr[j].activate << "," << singleIMEIarr[j].tempTime << "," << singleIMEIarr[j].tempDate;
          j = j + 1;  
          cout << endl ;
      } while (objschedule->FetchNextTuple() == true) ;
     
 
     cout << "PLANNAME,PLANDESCRIPTION,SCRIPTEXEC,STARTDATE,STARTIME,STOPDATE,STOPTIME,REPEATDELAY,NOTONWEEKEND,ACTIVATE" <<  "\n";
     
     for (int k=1; k <= 5; k++)
     {
         cout << singleIMEIarr[k].planName << "," << singleIMEIarr[k].planDescription << "," << singleIMEIarr[k].scriptExec << "," << singleIMEIarr[k].startDate << "," << singleIMEIarr[k].startTime << "," << singleIMEIarr[k].stopDate << "," << singleIMEIarr[k].stopTime << "," << singleIMEIarr[k].delayInterval << singleIMEIarr[k].repeatDelay << "," << singleIMEIarr[k].notOnWeekend << "," << singleIMEIarr[k].activate << "," << singleIMEIarr[k].tempTime << "," << singleIMEIarr[k].tempDate << "\n";
     }
 
     // delete schedSession1 ;
     
     // Deletes Session using Session Pool
     SessionPool::deletePool();
     
     return *singleIMEIarr;
     
     char info[50] = "PLAN DISPLAYED";
     writeLog(NULL,info);
     
  }
  catch(...)
  {
     char error[50] = "PLAN CANNOT BE DISPLAYED";
     writeLog(NULL,error);
     cout<<"Unknown Error";
     throw;
  }       
}

Error 20: "getPlanData.cpp", line 29 # ';' expected before '{'.
{
^
Error 187: "getPlanData.cpp", line 59 # Referenced object 'planName' is not a
member of class planList ["./schedule_MgmtC.h", line 216].
singleIMEIarr[j].planName=objschedule->GetColumnValue(i

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.