我是初学者 做作业 遇到问题
我写了这样的代码
为什么提示
D:\学习\c++\test\f1.cpp(12) : error C2065: 'dbproc' : undeclared identifier
执行 cl.exe 时出错.
我只是写在了类里边再调用阿 ? 类要怎样写才是正确的呢?
#define DBNTWIN32
#include <windows.h>
#include <sqlfront.h>
#include <sqldb.h>
#include <iostream.h>
class A
{
public:
void B()
{
dbuse(dbproc,"pubs");
dbcmd(dbproc,"select title_id,type,price from titles");
dbcmd(dbproc," order by type");
dbcmd(dbproc," compute avg(price),sum(price) by type");
dbcmd(dbproc," compute avg(price)");
if(dbsqlexec(dbproc)==FAIL)
{
cout<<"error sql statement!"<<endl;
exit(-2);
}
dbresults(dbproc);
dbprhead(dbproc);
dbprrow(dbproc);
cout<<endl;
}
};
void main()
{
DBPROCESS *dbproc;
LOGINREC *login;
login=dblogin();
char cname[20];
char cpassword[20];
cout<<"enter your name:";
cin>>cname;
cout<<"enter the password:";
cin.ignore();
cin.getline(cpassword,20);
DBSETLUSER(login,cname);
DBSETLPWD(login,cpassword);
dbproc=dbopen(login,NULL);
A a1;
a1.B();
}
參考答案:void B()改成
void B(DBPROCESS *dbproc)
a1.B()改成
a1.B(dbproc);