我只是想稍微修改一下 zeroc 的示例(带有打印机的示例)。所以这是怎么回事。
这是 Pritner.ice 文件中的小界面:
#pragma once
module Demo
{
interface Printer
{
void printString(string s);
void printFloat(float val);
};
};
以及产生错误的服务器端类。
#include <Ice/Ice.h>
#include <Printer.h>
using namespace std;
using namespace Demo;
class PrinterI : public Printer
{
public:
virtual void printString(const string &, const Ice::Current&);
virtual void printFloat(const float &, const Ice::Current&);
};
void
PrinterI::
printFloat(const float &val,const Ice::Current&)
{
cout<<val<<endl;
}
void
PrinterI::
printString(const string &s, const Ice::Current&)
{
cout << s << endl;
}
错误如下所示:
Server.cpp: In function ‘int main(int, char**)’:
Server.cpp:49:37: error: cannot allocate an object of abstract type ‘PrinterI’
Ice::ObjectPtr object = new PrinterI;
^
Server.cpp:16:7: note: because the following virtual functions are pure within ‘PrinterI’:
class PrinterI : public Printer
^
In file included from Server.cpp:11:0:
./Printer.h:430:18: note: virtual void Demo::Printer::printFloat(Ice::Float, const Ice::Current&)
virtual void printFloat(::Ice::Float, const ::Ice::Current& = ::Ice::Current()) = 0;
^
make: *** [Server.o] Error 1
主要代码:
int
main(int argc, char* argv[]){
int status = 0;
Ice::CommunicatorPtr ic;
try
{
ic = Ice::initialize(argc, argv);
Ice::ObjectAdapterPtr adapter =
ic->createObjectAdapterWithEndpoints("SimplePrinterAdapter", "default -h localhost -p 10000");
Ice::ObjectPtr object = new PrinterI;
adapter->add(object, ic->stringToIdentity("SimplePrinter"));
adapter->activate();
ic->waitForShutdown();
}
catch(const Ice::Exception& e)
{
cerr << e << endl;
status = 1;
}
catch(const char* msg)
{
cerr << msg << endl;
status = 1;
}
if(ic)
{
try
{
ic->destroy();
}
catch(const Ice::Exception& e)
{
cerr << e << endl;
status = 1;
}
}
return status;
}
printString 的部分很好并且运行良好,但是当我想在 intreface 的函数中使用 float 作为参数时,它会产生错误。我承认我不是 c++ 的专业人士,但我只是没有任何关于如何解决这个问题的线索。