2013-05-29 53 views
-1

代碼:Vertica的錯誤在編譯的C++程序:VerticaTypeâ沒有名爲âgetVarcharLengthâ成員

// Include the top-level Vertica SDK file 
#include "/opt/vertica/sdk/include/Vertica.h" 
#include <sstream> 
#include <iostream> 
using namespace Vertica; 
using namespace std; 
// Using the Vertica namespace means we don't have to prefix all 
// class references with Vertica:: 
using namespace Vertica; 
/* 
* ScalarFunction implementation for a UDSF that adds 
* two numbers together. 
*/ 
class Add2Ints : public ScalarFunction 
{ 
public: 
/* 
* This function does all of the actual processing for the UDF. 
* In this case, it simply reads two integer values and returns 
* their sum. 
* 
* The inputs are retrieved via arg_reader 
* The outputs are returned via arg_writer 
*/ 
    virtual void processBlock(ServerInterface &srvInterface, 
           BlockReader &arg_reader, 
           BlockWriter &res_writer) 
    { 
     // While we have input to process 
     do 
     { 
      // Read the two integer input parameters by calling the 
      // BlockReader.getIntRef class function 
      const vint a = arg_reader.getIntRef(0); 
      const vint b = arg_reader.getIntRef(1); 
      // Call BlockWriter.setInt to store the output value, which is 
      // two input values added together 
      res_writer.setInt(a+b); 
      // Finish writing the row, and advance to the next output row 
      res_writer.next(); 
      // Continue looping until there are no more input rows 
     } 
     while (arg_reader.next()); 
    } 
}; 
/* 
* This class provides metadata about the ScalarFunction class, and 
* also instantiates a member of that class when needed. 
*/ 
class Add2IntsFactory : public ScalarFunctionFactory 
{ 
    // return an instance of Add2Ints to perform the actual addition. 
    virtual ScalarFunction *createScalarFunction(ServerInterface &interface) 
    { 
     // Calls the vt_createFuncObj to create the new Add2Ints class instance. 
     return vt_createFuncObj(interface.allocator, Add2Ints); 
    } 

    virtual void getPrototype(ServerInterface &interface, 
           ColumnTypes &argTypes, 
           ColumnTypes &returnType) 
    { 
     // Takes two ints as inputs, so add ints to the argTypes object 
     argTypes.addInt(); 
     argTypes.addInt(); 
     // returns a single int, so add a single int to the returnType object. 
     // Note that ScalarFunctions *always* return a single value. 
     returnType.addInt(); 
    } 
}; 

// Determine the length of the varchar string being returned. 
virtual void Add2IntsFactory::getReturnType(ServerInterface &srvInterface,const SizedColumnTypes &argTypes,SizedColumnTypes &returnType) 
{ 
    const VerticaType &t = argTypes.getColumnType(0); 
    returnType.addVarchar(t.getVarcharLength()); 
} 
// Register the factory with Vertica 
RegisterFactory(Add2IntsFactory); 

錯誤:

之前 '::' 預計初始令牌

莫非你請幫忙?

+0

您的問題主體('預期初始值設定項之前::標記')和您的問題標題('VerticaType沒有成員VarcharLength')中的錯誤是不一樣的。這讓其他用戶感到困惑,他們看到標題後可能不會閱讀該問題。 –

+0

我很抱歉abt this ...將編輯這 – Gopu

回答

0

您的功能Add2IntsFactory::getReturnType在類之外聲明。你做不到。

+0

所以我該如何運行它..就像我應該再次指定類...這將是我需要添加的語法 – Gopu

+0

只需將此聲明移入類。 – soon

相關問題