Howto develop OO apps using ProC/C++ 2.2?
Date: Fri, 02 Apr 1999 15:20:33 -0400
Message-ID: <37051881.E903704D_at_hfx.andara.com>
Does anyone know how to use ProC/C++ to write C++ applications?
Here's my problem.
I have an "employee" class that has a single method "getSalary" which simply does a select from an emp table and returns the salary of the employee with the specified employee number.
I want to separate the interface from the implementation for this class by putting the interface in a file called "emp.h" and the implementation in a file called "emp.cc" (generated by ProC/C++ from "emp.pc").
I create a 3rd file called "main.cc" containing the main function which simply declares an instance of the employee class and invokes its "getSalary" method.
Both main.cc and emp.cc need to #include "emp.h".
Now here's the problem ...
My employee class should contain data members which correspond to the
rows in the emp table. These will include things like VARCHARS. Do I have
to parse my ".h" header file with the ProC/C++ precompiler? If not, how
can I get the proc compiler to recognize the host variables in the EXEC
SQL SELECT of the getSalary method in emp.pc?
I guess the bigger question is this:
Do I have to have to declare host variables in a special "EXEC SQL
BEGIN DECLARE SECTION" ?
If not, is it sufficient to just stick a colon in front of these variables
and call them "host variables"?
Pseudocode ...
/******************************************************************************/
main.cc:
#include emp.h
int
main(void)
{
emp employees;
cout << "Salary =
" << employees.getSalary("7439") << endl;
}
/******************************************************************************/
emp.h:
class emp
{
/* Does this go here? */
EXEC SQL BEGIN DECLARE SECTION;
...
EXEC SQL END DECLARE SECTION;
/* Or can I do this... ?
*/
int empno;
struct {
unsigned short len,
unsigned char arr[20]
}ename;
float salary;
public:
emp();
float getSalara(int empno);
}
/******************************************************************************/
emp.pc: (--> emp.cc)
emp()
{
...
empno = 0;
ename.arr[0] = '\0';
salary = 0.0;
..
}
getSalary(int empno)
{
...
SELECT sal
INTO :salary
FROM emp
WHERE empno=:emp_number;
...
}
/******************************************************************************/ Received on Fri Apr 02 1999 - 21:20:33 CEST