Problem with decalaration of TBuf8 ???

Login to reply to this topic.
Sun, 2005-08-07 14:25
Joined: 2005-07-07
Forum posts: 34
Hi All,

How can I declare:

int i = 10;
TBuf8 buf;

now compiler give me error:
error C2971: 'TBuf8' : template parameter 'S' : 'i' : a local variable cannot be used as a non-type argument

when I make i global variable the error is following:

error C2975: 'S' : invalid template argument for 'TBuf8', compile-time evaluatable constant expression expected

thanks !

Mon, 2005-08-08 04:01
Joined: 2005-03-15
Forum posts: 94
Re: Problem with decalaration of TBuf8 ???
TBuf is usually used for buffers of fixed lengths, hence you should use the following way:
TBuf8<10> buf;

But, if you are looking for some dynamic buffer, then you could explore using HBufC.

Vivek

Vivek Chopra

Mon, 2005-08-08 06:58
Joined: 2004-12-03
Forum posts: 192
Re: Problem with decalaration of TBuf8 ???
compiler has to know the amount of memory to allocate
try
Code:
const int i = 10;
TBuf8<i> buf;
or use HBufC, as vivekchopra said, if you want to change the length dynamically
Mon, 2005-08-08 08:09
Joined: 2005-06-11
Forum posts: 85
Re: Problem with decalaration of TBuf8 ???
TBuf8 takes const value as parameter....the i you are providing is not const...thats why you are getting error....

Wise People talk because they have something to say . Fools talk because thay have to say somthing.

Mon, 2005-08-08 16:19
Joined: 2005-07-07
Forum posts: 34
Re: Problem with decalaration of TBuf8 ???
Thanks Vivek,

I use HBufC8 for dynamic buffer and this solve my problem

Thanks again Smiley
  • Login to reply to this topic.