structure

Changing Class Variables in runtime?

若如初见. 提交于 2020-01-07 04:25:07
问题 Let me give an idea of what I wish to do: I have a structure or class called student , which contains variables like int roll_no and int reg_no If the user wishes to add a new variable like char name at run time how can it be done? 回答1: Based on the word "Structure" and the variable declarations, I'm going to guess this question is about some flavor of C. How exactly to do this will depend on the language, but as a general rule, if the language is compiled (e.g. C/C++, Java), this is not

Checking a string for adjacent characters on the keyboard

一笑奈何 提交于 2020-01-07 03:07:24
问题 I'm trying to check consecutive characters in a string to see if they are adjacent on the keyboard. It's part of a program that I am writing to assess password strength. I have this code that initializes the keyboard as an array: KeyboardRow1 = ["`", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0", "-", "=", ""] KeyboardRow2 = ["", "q", "w", "e", "r", "t", "y", "u", "i", "o", "p", "[", "]", ""] KeyboardRow3 = ["", "a", "s", "d", "f", "g", "h", "j", "k", "l", ";", "", "", ""] KeyboardRow4 = [

Accessing a structure variable double pointer

£可爱£侵袭症+ 提交于 2020-01-06 08:46:11
问题 Some code: typedef struct _WDF_USB_DEVICE_SELECT_CONFIG_PARAMS { ULONG Size; WdfUsbTargetDeviceSelectConfigType Type; union { struct { PUSB_CONFIGURATION_DESCRIPTOR ConfigurationDescriptor; PUSB_INTERFACE_DESCRIPTOR* InterfaceDescriptors; ULONG NumInterfaceDescriptors; } Descriptor; struct { PURB Urb; } Urb; } Types; } WDF_USB_DEVICE_SELECT_CONFIG_PARAMS,*PWDF_USB_DEVICE_SELECT_CONFIG_PARAMS; WDF_USB_DEVICE_SELECT_CONFIG_PARAMS params; typedef struct _USB_INTERFACE_DESCRIPTOR { UCHAR bLength

Generic Function with (Of T as What?) to accept String, Integer, DateTime?

北战南征 提交于 2020-01-06 03:03:09
问题 I've got this Function: Public Class QueryStringUtil Public Shared Function GetQueryStringValue(Of T As Structure)(ByVal queryStringVariable As String) As T Dim queryStringObject As Nullable(Of T) = Nothing If queryStringVariable <> Nothing Then If HttpContext.Current.Request.QueryString(queryStringVariable) IsNot Nothing Then queryStringObject = CTypeDynamic(Of T)(queryStringVariable) End If End If Return queryStringObject End Function End Class When I try to call it like this: Dim intTest

Marshaling structure to single line of string

可紊 提交于 2020-01-05 12:34:54
问题 [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)] public class Comarea { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 1)] public string status; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 5)] public string operationName; } public static void StringToObject(string buffer, out Comarea comarea) { IntPtr pBuf = Marshal.StringToBSTR(buffer); comarea = (Comarea)Marshal.PtrToStructure(pBuf, typeof(Comarea)); } I can create object from single line of string but I can not do

Why is forward declaration of structure not working in my code? When can it be used in C?

旧城冷巷雨未停 提交于 2020-01-05 10:28:33
问题 Isn't forward declaration, whether for structures or functions, supposed to do what forward declaration is expected to do, ie, to let us use the structure or function before they are defined? Why is the forward declaration of a structure not working in my code? And the main thing that just misses me, is forward declaration of structures of any use in C at all? When is it used? Can you please give me a small C program example to illustrate this? My program gives the error error: storage size

Reference to unwrapped property fails: use of partially moved value: `self`

天大地大妈咪最大 提交于 2020-01-05 07:43:39
问题 I try to send an unwrapped string reference to a static method implemented for a struct. Here is a simplified code: fn main() { let a = A {p: Some("p".to_string())}; a.a(); } struct A { p: Option<String> } impl A { fn a(self) -> Self { Self::b(&self.p.unwrap()); self } fn b(b: &str) { print!("b: {}", b) } } It fails: error[E0382]: use of partially moved value: `self` --> src/main.rs:14:13 | 13 | Self::b(&self.p.unwrap()); | ------ value moved here 14 | self | ^^^^ value used here after move |

Dereference a structure to get value of first member

浪子不回头ぞ 提交于 2020-01-05 07:12:13
问题 I found out that address of first element of structure is same as the address of structure. But dereferencing address of structure doesn't return me value of first data member. However dereferencing address of first data member does return it's value. eg. Address of structure=100, address of first element of structure is also 100. Now dereferencing should work in the same way on both. Code: #include <iostream> #include <cstring> struct things{ int good; int bad; }; int main() { things *ptr =

Dereference a structure to get value of first member

两盒软妹~` 提交于 2020-01-05 07:11:40
问题 I found out that address of first element of structure is same as the address of structure. But dereferencing address of structure doesn't return me value of first data member. However dereferencing address of first data member does return it's value. eg. Address of structure=100, address of first element of structure is also 100. Now dereferencing should work in the same way on both. Code: #include <iostream> #include <cstring> struct things{ int good; int bad; }; int main() { things *ptr =

Passing a Structure containing an array of String and an array of Integer into a C++ DLL

自作多情 提交于 2020-01-05 07:10:36
问题 I'm having problems with marshaling in VB.NET to C++, here's the code : In the C++ DLL : struct APP_PARAM { int numData; LPCSTR *text; int *values; }; int App::StartApp(APP_PARAM params) { for (int i = 0; i < numLines; i++) { OutputDebugString(params.text[i]); } } In VB.NET : <StructLayoutAttribute(LayoutKind.Sequential)> _ Public Structure APP_PARAM Public numData As Integer Public text As System.IntPtr Public values As System.IntPtr End Structure Declare Function StartApp Lib "AppSupport