Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / Managed C++ / October 2004

Tip: Looking for answers? Try searching our database.

[CLI-C++] Using sizeof inside a generic function

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
marco_segurini - 18 Oct 2004 15:05 GMT
Hi,

I like to know if is it possible to use sizeof(T) inside a generic
function.

I don't know why the following function compiles while if I define
ON_LINE_STATEMENT it does not.

generic<typename T>
void CopyArrayFromArray(array<T>^ % vVal, int size
                      , array<Byte>^ vBytes, int % PosNextValidByte)
{
  vVal = gcnew array<T>(size);
  pin_ptr<T> ptrDest = &vVal[0];
  pin_ptr<Byte> ptrBytes = &vBytes[PosNextValidByte];
#if defined(ONE_LINE_STATEMENT)
  const Int32 NumBytesDaCopiare = size * sizeof(T);
#else
  Int32 NumBytesDaCopiare = sizeof(T);
  NumBytesDaCopiare *= size;
#endif
  memcpy(ptrDest, ptrBytes, NumBytesDaCopiare);
  PosNextValidByte += NumBytesDaCopiare;
}

TIA.
Marco.
Ioannis Vranos - 18 Oct 2004 15:41 GMT
> Hi,
>
[quoted text clipped - 20 lines]
>    PosNextValidByte += NumBytesDaCopiare;
> }

The current C++/CLI draft says about sizeof():

"15.4.3 Sizeof

The C++ Standard (§5.3.3/1) has been extended, as follows:

“The sizeof operator shall not be applied to an expression that has
function or incomplete type, or to an enumeration type before all its
enumerators have been declared, or to the parenthesized name of such
types, or to an lvalue that designates a bit-field, or to an expression
that has null type, or to a handle, or to a tracking reference, or to a
ref class."

Signature

Ioannis Vranos


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.