declaration

arrayVariable() As Object vs. arrayVariable As Object() – not the same in Property declaration?

╄→尐↘猪︶ㄣ 提交于 2019-12-07 01:04:36
Until today, I thought that the following two notations are the same (edit: Dim was replaced by Property ) Property arrayVariable() As Object Property arrayVariable As Object() Today I found that former one throws error Option Strict On disallows late binding. while the latter compiles OK in expression dictionary1.TryGetValue(CStr(arrayVariable(0)), result) . Please what is the difference between them? I would always use the second notation if it also allowed to specify the array dimensions. It doesn't, so I stuck with the first form (less clean one, because part of type specification -

2D Array Value Assign After Declaration in C++

与世无争的帅哥 提交于 2019-12-06 23:13:23
I know when we want to assign values to 2D arrays as we declare the array, we do this: int myArray[2][4] = {{1,2,3,4},{5,6,7,8}}; But how should I assign values "after" declaring it? I want to do something like this: int myArray[2][4]; myArray = {{1,2,3,4},{5,6,7,8}}; When I do it, the compiler gives error. Help please. If you want to use std::vector then you can do this: #include <vector> int main() { std::vector< std::vector<int> > arrV ; arrV = { {1,2,3,4}, {5,6,7,8} }; } or using std::array : #include <array> int main() { std::array<std::array<int,4>,2> arr ; arr = {{ {{1,2,3,4 }}, {{5,6,7

Is Type name = name; ever useful in C++?

你离开我真会死。 提交于 2019-12-06 19:08:13
问题 The following code is allowed in C++: int a = a; or Type name = name; Both lead to an uninitialized object being initialized by itself, which often leads to undefined behavior. Is such code ever needed or reasonable? Are there cases of such code being useful? 回答1: You are allowed to use the name of the variable in its initializer. The code Type name = name; is probably not useful, but the code Type name = f(&name); might be. There are many places where the language syntax doesn't forbid

How to use enum within a struct in ANSI C?

喜欢而已 提交于 2019-12-06 19:02:56
问题 Following code has to be used in the main-function, but I don't know how it is used. struct SomeItem { enum {MOVIE, MUSIC} itemType; union { struct Movie* movie; struct Music* music; }; }; this struct is used in a dynamic linked list with previous/item/next pointer, but I don't know how you can set the enum. Or how to initialize it. I need to know how it would look like in the main-function. biglist.someitem = ???; /* declaration I use */ struct Library* biglist; more code to understand what

Why does this Perl variable keep its value

爷,独闯天下 提交于 2019-12-06 11:59:12
What is the difference between the following two Perl variable declarations? my $foo = 'bar' if 0; my $baz; $baz = 'qux' if 0; The difference is significant when these appear at the top of a loop. For example: use warnings; use strict; foreach my $n (0,1){ my $foo = 'bar' if 0; print defined $foo ? "defined\n" : "undefined\n"; $foo = 'bar'; print defined $foo ? "defined\n" : "undefined\n"; } print "==\n"; foreach my $m (0,1){ my $baz; $baz = 'qux' if 0; print defined $baz ? "defined\n" : "undefined\n"; $baz = 'qux'; print defined $baz ? "defined\n" : "undefined\n"; } results in undefined

Difficulty in understanding variable-length arrays in C

倾然丶 夕夏残阳落幕 提交于 2019-12-06 07:05:41
问题 I was reading a book when I found that array size must be given at time of declaration or allocated from heap using malloc at runtime.I wrote this program in C : #include<stdio.h> int main() { int n, i; scanf("%d", &n); int a[n]; for (i=0; i<n; i++) { scanf("%d", &a[i]); } for (i=0; i<n; i++) { printf("%d ", a[i]); } return 0; } This code works fine. My question is how this code can work correctly.Isn't it the violation of basic concept of C that array size must be declared before runtime or

C++ variable declaration and initialization rules

ⅰ亾dé卋堺 提交于 2019-12-06 06:49:56
问题 Consider the following ways of declaring and initializing a variable of type C : C c1; C c2; c2 = C(); C c3(C()); C c4 = C(); Are all of these completely equivalent to each other, or can some of these differ depending on the exact definition of C ? (assuming it has public default and copy constructors). 回答1: These mean: C c1; // default constructor C c2; // default constructor c2 = C(); // default constructor followed by assignment C c3(C()); // default constructor possibly followed by copy

“required from here” error declaring a List of Lists

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-06 05:49:51
I'm trying to declare a list of lists in this way: List_vector<List_vector<int> > multilist; But Eclipse underlines the above declaration and gives this error: required from here Partial List_vector implementation: template<class T> class List_vector: public Linear_list<T, int> { public: typedef typename Linear_list<T, int>::value_type value_type; typedef typename Linear_list<T, int>::position position; List_vector(); List_vector(int); List_vector(const List_vector<T>&); ~List_vector(); private: void change_dimension_(T*&, int, int); value_type* elements_; int length_; // the length of the

C++ Do I need to write throw clause for a function everywhere?

我怕爱的太早我们不能终老 提交于 2019-12-05 15:57:13
Before Consider to have a class and a global function: This is, for example, usefulfuncts.hpp void dosome(int a, int b) throw (std::exception); This is usefulfuncts.cpp void dosome(int a, int b) throw (std::exception) { //... } And this is aclass.hpp class aclass { // Members... friend void dosome(int a, int b) throw (std::exception); // Members... }; After (what I would like that to be) Ok! I would like to understand if it is strictly necessary to write everytime the throw clause. So for example can I do this? This is usefulfuncts.hpp void dosome(int a, int b) throw (std::exception); This is

Difference between int and signed int declaration

 ̄綄美尐妖づ 提交于 2019-12-05 15:52:22
问题 I am reading some tutorials on embedded programming and one of them says int and signed int are different but does not explain how or why. I understand why unsigned int and int are different but int and signed int being different is a new one for me. 回答1: It is for historical reasons only. Today whenever you declare int you get a signed int . The only point where you might see a difference even with today's compilers is with char versus signed char which are different by specification (and