问题描述
我有一个结构,并定义了一个指向结构的智能指针。
/ *开始文档索引记录的结构* /
typedef struct BDI_Struct {
unsigned char rname;
unsigned short int rlen;
int code;
short int reserved;
char indexName [9];
unsigned char tripLen;
unsigned char tripCode;
TRIPLET01 t01;
} BDIStruct;
/ *索引元素记录的结构* /
typedef struct记录{
unsigned char rname;
unsigned short int rlen;
int code;
short int reserved;
unsigned char tripLen;
unsigned char tripCode;
union
{
TRIPLET01 t01;
TRIPLET57 t57;
TRIPLET2D t2D;
TRIPLET36 t36;
TRIPLET02 t02;
TRIPLET80 t80;
TRIPLETGEN tgen;
} TRec;
} IndexStr uct;
定义智能指针如下:
其中ObjVar返回指针。
typedef ObjVar< IELStruct> IELStruct_sptr;
typedef ObjVar< BDIStruct> BDIStruct_sptr;
现在,当我将智能指针传递给函数时,我得到编译
错误
我正在通过智能指针为
int vValidateIndModcaFile(ObjVar< BDIStruct>& bdirec,ObjVar< IndexStruct>&
ielrec);
这是通过智能指针的正确方法。
你能不能指导我。
我得到了错误喜欢
" /vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp" ;,第68.11行:
1540-1101(W)返回值输入BDI_Struct *预计。
" /vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp" ;,第63.12行:
1540-0700(I)上一条消息是在处理
" ObjVar< BDI_Struct> :: operator->()"。
" IndOutModcaParser.cpp",第1814.5行:1540-0700(I)上一条消息
是在处理时生成的。
" CIndOutModcaParser :: vValidateIndModcaFile(ObjVar< BDI_Struct>&,
ObjVar< record>& ;)" ;.
" /vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp" ;,第68.11行:
1540-1101(W)返回值输入record *预计。
" /vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp" ;,第63.12行:
1540-0700(I)上一条消息是在处理
" ObjVar< record> :: operator->()"。
" IndOutModcaParser.cpp",第1814.5行:1540-0700(I)上一条消息
是在处理时生成的。
" CIndOutModcaParser :: vValidateIndModcaFile(ObjVar< BDI_Struct>&,
ObjVar< record>& ;)
谢谢,
Lokb
声明''vValidateIndModcaFile''函数不是为了
责备。更有可能的是''ObjVar''模板与编译器所期望的
不相上下。
Victor
如果没有看到ObjVar的定义,似乎无法回答关于如何使用它的
问题。智能指针就像任何其他的类一样,你如何使用它们取决于它们的编写方式。
你所写的内容肯定适用于一些智能指针类
我已经看过,但是为什么它不适合你的智能指针只能在没有看到智能指针类的代码的情况下猜到。 br />
john
Hi,
I have a structure which and defined a smart pointer to the structure.
/* Structure of Begin Document Index Record */
typedef struct BDI_Struct{
unsigned char rname;
unsigned short int rlen;
int code;
short int reserved;
char indexName[9];
unsigned char tripLen;
unsigned char tripCode;
TRIPLET01 t01;
}BDIStruct;
/* Structure of Index Element Record */
typedef struct record{
unsigned char rname;
unsigned short int rlen;
int code;
short int reserved;
unsigned char tripLen;
unsigned char tripCode;
union
{
TRIPLET01 t01;
TRIPLET57 t57;
TRIPLET2D t2D;
TRIPLET36 t36;
TRIPLET02 t02;
TRIPLET80 t80;
TRIPLETGEN tgen;
}TRec;
}IndexStruct;
Defined the smart pointer as below:
where ObjVar returns the pointer.
typedef ObjVar<IELStruct> IELStruct_sptr;
typedef ObjVar<BDIStruct> BDIStruct_sptr;
Now when i am passing the smart pointers to the function i get compilation
errors
I am passing the smart pointers as
int vValidateIndModcaFile(ObjVar<BDIStruct>& bdirec,ObjVar<IndexStruct>&
ielrec);
Is it the right way to pass the smart pointers.
Could you plz guide me.
I am getting the erros like
"/vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp", line 68.11:
1540-1101 (W) A return value of type "BDI_Struct *" is expected.
"/vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp", line 63.12:
1540-0700 (I) The previous message was produced while processing
"ObjVar<BDI_Struct>::operator->()".
"IndOutModcaParser.cpp", line 1814.5: 1540-0700 (I) The previous message
was produced while processing
"CIndOutModcaParser::vValidateIndModcaFile(ObjVar< BDI_Struct> &,
ObjVar<record> &)".
"/vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp", line 68.11:
1540-1101 (W) A return value of type "record *" is expected.
"/vpapp/accenture/ISIXRelease1206302004/include/sptr.hpp", line 63.12:
1540-0700 (I) The previous message was produced while processing
"ObjVar<record>::operator->()".
"IndOutModcaParser.cpp", line 1814.5: 1540-0700 (I) The previous message
was produced while processing
"CIndOutModcaParser::vValidateIndModcaFile(ObjVar< BDI_Struct> &,
ObjVar<record> &)"
Thanks,
Lokb
The declaration of the ''vValidateIndModcaFile'' function is not to
blame. More likely the ''ObjVar'' template is not up to par with what
the compiler expects from it.
Victor
Without seeing the defintion of ObjVar it seems impossible to answer your
question about how to use it. Smart pointers are classes just like any
other, how you use them depends on how they are written.
What you have written would certainly work with some smart pointer classes
I have seen, but why it isn''t OK with your smart pointer can only be
guessed at without seeing the code of your smart pointer class.
john
这篇关于如何将智能指针传递给函数。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!