reference

Java: setting a reference to null won't affect the object

限于喜欢 提交于 2020-01-01 11:34:31
问题 I've got a simple question. In this code below, why is s3's value still printed although I set it to null before. It seems gargbage collector won't get called. public class Test { public static void main(String[] args) { String s1 = "abc", s2 = "def", s3 = "ghj"; String sarr[] = {s1, s2, s3}; s3 = null; System.gc(); for(int i = 0; i < sarr.length; i++) { System.out.print(sarr[i] + " "); //prints abc def ghj } } } Any thoughts would be appreciated. 回答1: When you write: // Moved [] to make it

“Undefined reference to” using Lua

不羁的心 提交于 2020-01-01 10:46:07
问题 I got the error undefined reference to 'luaL_newstate' when I try to build my project. I know it's an error with the linker but I'm relatively new to Lua and adding a library to a project. I use Code::Blocks by the way. API functions luaL_openlibs , luaL_loadfile , lua_pcall , lua_getfield , lua_type , lua_settop are missing too. I saw on a webite that I have to link my project with libdl in order to solve this problem, but I don't really know what it mean and how to do it. 回答1: I faced the

Is it possible to delete the object itself, not the reference

别等时光非礼了梦想. 提交于 2020-01-01 10:09:26
问题 var a = { "example" : true }; var x = [a], y = [a]; delete x[0]; console.log(y); In the above code, would it be possible to have a deleted, not just the reference in x ? 回答1: That's up to the garbage collector. As long as there's some reference to the object, it will not be garbage collected. If you want it to be cleaned up, make sure there are no more references. So to answer your question, no, there's no way to explicitly destroy an object. If a and y[0] are still referencing it, you can't

How can I take a reference to a Perl subroutine?

时光毁灭记忆、已成空白 提交于 2020-01-01 08:43:25
问题 I'm having some trouble figuring out how to make a reference to a subroutine in an external module file. Right now, I'm doing this: External file package settingsGeneral; sub printScreen { print $_[0]; } Main use settingsGeneral; my $printScreen = settingsGeneral::printScreen; &$printScreen("test"); but this result into an error: Can't use string ("1") as a subroutine ref while "strict refs" in use 回答1: As noted in perlmodlib, you should start your module's name with an uppercase letter: Perl

C++ Pass a reference to an array to function

时光总嘲笑我的痴心妄想 提交于 2020-01-01 06:33:08
问题 Given to functions void main() and void hello(byte* a[4]). Main function has an array of four bytes. The array's reference needs to be passed to the function hello for manipulation. I would expect the right syntax to be: void hello(byte* a[4]){ // Manipulate array a[0] = a[0]+1; } void main(){ byte stuff[4] = {0,0,0,0}; hello(&stuff); // hopefully stuff is now equal {1,0,0,0} } Alternatively I see others using this form of decaration: void hello(byte (&a)[4]) Is this the right way to do it?

.NET Assembly Dependencies

冷暖自知 提交于 2020-01-01 05:27:20
问题 Perhaps I am missing something obvious here but... I have built a reusable generic C# class library project say (A.dll) which references 3 other assemblies say (B.dll, C.dll and D.dll) However if I want to reuse my component A.dll in another project I still have to include the references to B.dll, C.dll and D.dll. Is there any way you can configure A.dll to build all its dependencies into the A.dll so I don't have to include the other 3 assemblies? Cheers 回答1: It's possible to merge

c++ passing a string literal instead of a const std::string&?

*爱你&永不变心* 提交于 2020-01-01 05:08:13
问题 I have the following code which compiles with no warnings (-Wall -pedantic) with g++ #include <iostream> #include <string> using namespace std; class Foo { public: Foo(const std::string& s) : str(s) { } void print() { cout << str << endl; } private: const std::string& str; }; class Bar { public: void stuff() { Foo o("werd"); o.print(); } }; int main(int argc, char **argv) { Bar b; b.stuff(); return 0; } But when I run it, only the newline is printed out. What is going on? If I were to do this

Referencing another project in .Net Core

一世执手 提交于 2020-01-01 04:48:07
问题 I have 6 projects in a blank solution. I just want to reference a project to another. I have HomeController in Blog.Web projects. I want to access another project's methods like IOrganizationService in Blog.Services projects. How can I use IOrganization's method in HomeController class? For clear insight, please see picture. Red marks show the errors.... 回答1: It looks like you've created everything as web sites, but I suspect that most of those projects should actually be class libraries

Does this C++ static analysis rule make sense as is?

主宰稳场 提交于 2020-01-01 04:24:26
问题 I'm implementing some C++ static analysis rules, and one of them prohibits a function from returning a reference or pointer to a reference parameter of the function, i.e. the following are all non-compliant: int *f(int& x) { return &x; } // #1 const int *g(const int& x) { return &x; } // #2 int& h(int& x) { return x; } // #3 const int& m(const int& x) { return x; } // #4 The justification given for this is that "It is implementation-defined behaviour whether the reference parameter is a

Why doesn't C++11 curly brace initialzation in constructor initialization list work when parens initializaton does?

拜拜、爱过 提交于 2020-01-01 04:21:46
问题 How is {} initialization in a constructor initialization list different from () initialization when initializing reference to abstract types? Take class Bar below: class AbstractBase { public: AbstractBase() {} virtual ~AbstractBase() = default; virtual void ab() = 0; }; class Foo : public AbstractBase { public: Foo() {} void ab() {} }; class Bar { public: Bar(const AbstractBase& base) : myBase{base} {} private: const AbstractBase& myBase; }; int main() { Foo f{}; Bar b{f}; } When compiling,