initialization

Initialization section of the package

时间秒杀一切 提交于 2020-02-02 12:05:44
问题 This is the package specification: CREATE OR REPLACE PACKAGE employee_info IS PROCEDURE p; FUNCTION f RETURN BOOLEAN; END employee_info; This is the package body: CREATE OR REPLACE PACKAGE body employee_info IS PROCEDURE p IS BEGIN dbms_output.put_line('This is procedure'); dbms_output.put_line(chr(10)); END; FUNCTION f RETURN BOOLEAN IS BEGIN dbms_output.put_line('This is function '); dbms_output.put_line(chr(10)); RETURN true; END; BEGIN dbms_output.put_line('This is the initialization

Is it allowed to call a non-static member function in a default member initializer?

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-02 11:27:12
问题 Consider this class: #include <iostream> struct foo { int a = 42; int b = bar(); int bar() { return a; } }; int main(){ foo f; std::cout << f.a << " " << f.b; } It prints the expected 42 42 . Is it allowed by the standard to call a member function in a default member initializer? The following I would expect to be undefined: struct broken { int a = bar(); int b = 42; int bar() { return b; } }; Unfortunately it does compile without warnings. 回答1: As you found, this is legal, but brittle and

How to initialize a unique_ptr

别等时光非礼了梦想. 提交于 2020-01-31 06:16:25
问题 I'm trying to add a lazy-initialization function to my class. I'm not very proficient with C++. Can someone please tell me how I achieve it. My class has a private member defined as: std::unique_ptr<Animal> animal; Here's the original constructor that takes one parameter: MyClass::MyClass(string file) : animal(new Animal(file)) {} I just added a parameter-less constructor and an Init() function. Here's the Init function I just added: void MyClass::Init(string file) { this->animal = ???; }

How to initialize a unique_ptr

天大地大妈咪最大 提交于 2020-01-31 06:16:13
问题 I'm trying to add a lazy-initialization function to my class. I'm not very proficient with C++. Can someone please tell me how I achieve it. My class has a private member defined as: std::unique_ptr<Animal> animal; Here's the original constructor that takes one parameter: MyClass::MyClass(string file) : animal(new Animal(file)) {} I just added a parameter-less constructor and an Init() function. Here's the Init function I just added: void MyClass::Init(string file) { this->animal = ???; }

Java variable may not have been initialized

对着背影说爱祢 提交于 2020-01-30 07:08:45
问题 I'm working on Project Euler Problem 9, which states: A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a^2 + b^2 = c^2 For example, 3^2 + 4^2 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000. Find the product abc. Here's what I've done so far: class Project_euler9 { public static boolean determineIfPythagoreanTriple(int a, int b, int c) { return (a * a + b * b == c * c); } public static void main(String[] args) { boolean

Why can't I access a member of this class? [duplicate]

最后都变了- 提交于 2020-01-30 05:57:05
问题 This question already has answers here : My attempt at value initialization is interpreted as a function declaration, and why doesn't A a(()); solve it? (5 answers) Closed 6 years ago . I have the following three class definitions: class String { public: String() {} String(const char *) {} }; class ClassA { public: ClassA(const String &) {} }; class ClassB { public: ClassB(const ClassA &, const String & = String()) {} void method() {} }; Now suppose I want to create an instance of ClassB :

How to initialize a struct in C# [duplicate]

こ雲淡風輕ζ 提交于 2020-01-28 09:40:54
问题 This question already has answers here : C# Structs: Unassigned local variable? (2 answers) Closed 2 years ago . I have some code to initialize a struct in C#: namespace Practice { public struct Point { public int _x; public int _y; public int X { get { return _x; } set { _x = value; } } public int Y { get { return _y; } set { _y = value; } } public Point(int x, int y) { _x = x; _y = y; } } class Practice { public static void Main() { Point p1; p1.X = 1; p1.Y = 2; } } } The above code gives a

How to initialize a struct in C# [duplicate]

独自空忆成欢 提交于 2020-01-28 09:39:28
问题 This question already has answers here : C# Structs: Unassigned local variable? (2 answers) Closed 2 years ago . I have some code to initialize a struct in C#: namespace Practice { public struct Point { public int _x; public int _y; public int X { get { return _x; } set { _x = value; } } public int Y { get { return _y; } set { _y = value; } } public Point(int x, int y) { _x = x; _y = y; } } class Practice { public static void Main() { Point p1; p1.X = 1; p1.Y = 2; } } } The above code gives a

Firebase Android - Skipping initialization

拟墨画扇 提交于 2020-01-26 04:09:06
问题 I am currently implementing an Android app, which uses Firebase Cloud Messaging. I've implemented everything according to the tutorial on the Firebase page. However, whenever I try to run my app it seems like the Firebase initialization fails. Both, on an emulator and on a real device I get this debug message: D/FirebaseApp: com.google.firebase.auth.FirebaseAuth is not linked. Skipping initialization. W/InstanceID/Rpc: Found 10010 D/FirebaseApp: com.google.firebase.crash.FirebaseCrash is not

How to pass method result as parameter to base class constructor in C++?

£可爱£侵袭症+ 提交于 2020-01-24 19:05:30
问题 I've trying to achieve something like this: class Base { public: Base(string S) { ... }; } class Derived: Base { public: int foo; string bar() { return stringof(foo); // actually, something more complex }; Derived(int f) : foo(f), Base(bar()) { }; } Now, this doesn't work as I want, because bar() is called in the Derived constructor before foo is initialized. I considered adding a static function similar to bar() which takes foo as a parameter - and using that in the initialization list, but