In this class, I am setting elp to ElType in the constructor.
I can access properties of elp fine when in the constructor (the // ... bit is where I'm accessing elp's properties), but when I try to access elp in another method - ucp() - my program crashes with NullReferenceException.
I can't figure out what I'm doing wrong here, althou...
Is there a copy constructor in python ? If not what would I do to achieve something similar ?
The situation is that I am using a library and I have extended one of the classes there with extra functionality and I want to be able to convert the objects I get from the library to instances of my own class.
...
As some of my code required implicit conversion between matrices of different types (e.g. Matrix<int> to Matrix<double>), I defined a templated copy constructor Matrix<T>::Matrix(Matrix<U> const&) instead of the standard Matrix<T>::Matrix(Matrix<T> const&):
template <typename T> class Matrix {
public:
// ...
template <typename U...
In a script a method receives a parameter of type File, and sends it to the constructor of File. This blows up because File doesn't have a constructor that takes another file as a parameter.
How can I intercept this call, and modify the parameter to parameter.absolutePath ?
For example :
def x = new File("some_file")
...
def meth(de...
Suppose I have a class with 3 constructors, a default (no argument) constructor, a parameterized constructor, and a static constructor. like this:
public MyClass() { ... }
public MyClass(string arg) : this() { ... }
static MyClass() { ... }
Supposing I invoke the parameterized constructor, in what order do these constructors ex...
Hello,
Jon Skeet's excellent article at http://www.yoda.arachsys.com/csharp/singleton.html and other articles I've read make it clear that that double-check locking doesn't work in both C# and Java unless one explicitly marks the instance as "volatile." If you don't, the check of comparing it to null could possibly return false even tho...
Hi,
I'm working on some C++ code and I've run into a question which has been nagging me for a while... Assuming I'm compiling with GCC on a Linux host for an ELF target, where are global static constructors and destructors called?
I've heard there's a function _init in crtbegin.o, and a function _fini in crtend.o. Are these called by c...
What does the colon operator (":") do in this constructor? Is it equivalent to MyClass(m_classID = -1, m_userdata = 0);?
class MyClass {
public:
MyClass() : m_classID(-1), m_userdata(0) {
}
int m_classID;
void *m_userdata;
};
...
I want the api of my module to only throw MyPackageSpecificException whenever anything goes wrong and the module unable to perform its task. (The original exception will be given as the cause of the MyPackageSpecificException).
Now, for one constructor I needed an URL as a parameter to locate a resource. I would also like to make an alt...
Mocking a concrete class with Rhino Mocks seems to work pretty easy when you have an empty constructor on a class:
public class MyClass{
public MyClass() {}
}
But if I add a constructor that takes parameters and remove the one that doesn't take parameters:
public class MyClass{
public MyClass(MyOtherClass instance) {}
}
I...
Why does this produce a compiler error:
class Foo
{
public Bar Baz = new Bar(this);
}
But this does not:
class Foo
{
public Bar Baz;
public Foo()
{
this.Baz = new Bar(this);
}
}
Conceptually the two are equivalent, are they not?
...
I have a strong feeling that I do not know what pattern or particular language technique use in this situation.
So, the question itself is how to manage the growing parameter list in class hierarchy in language that has OOP support? I mean if for root class in the hierarchy you have, let's say 3 or 4 parameters, then in it's derived clas...
Consider the following class,
class Foo
{
public Foo(int count)
{
/* .. */
}
public Foo(int count)
{
/* .. */
}
}
Above code is invalid and won't compile. Now consider the following code,
class Foo<T>
{
public Foo(int count)
{
/* .. */
}
public Foo(T t)
{
/...
I have the following class:
private class Info{
public String A;
public int B;
Info(){};
public OtherMethod(){};
private PrivMethod(){};
}
And I want to create an array of this class, but I want to provide a two dimensional array as an argument to the constructor, ie:
Info[] I = new Info({{"StringA", 1}, {"Strin...
I want to make a constructor function that creates a documentElement object.
As an example, consider the new Audio() constructor - it creates a documentElement object, and if you pass it some variables it populates the new documentElement with attributes. It doesn't insert it into the DOM, it simply creates the object.
So, the questio...
Hi,
I was debating with some colleges about what happens when you throw an exception in a dynamically allocated class. I know that malloc gets called, and then the constructor of the class. The constructor never returns, so what happens to the malloc?
Consider the following
class B
{
public:
B()
{
cout << "B::B()" ...
I'm using GetParameter to determine what parameters the constructor needs. I can get a list of them. Now I want to invoke the ctor. Is this possible if there is no empty one?
...
For example, compare these two:
function Person(name) {
this.name = name;
}
var john = new Person('John');
console.log(john.constructor);
// outputs: Person(name)
var MyJSLib = {
Person : function (name) {
this.name = name;
}
}
var john2 = new MyJSLib.Person('John');
console.log(john2.constructor);
// outputs: function()
The fi...
I hit a snag today... I wanted to define a small templated helper class:
template<class T>
CMyClass
{
public :
CMyClass() { size_t iSize = sizeof(T); } // Allowed.
size_t GetElementSize() const { return sizeof(T); } // C2027.
};
and of course, it wouldn't compile (C2027). My question was, is it possible to get the size of t...
Assuming you had some kind of factory-created resource that would still belong to the factory after construction like this:
public class Resource : IDisposable {
public void Dispose() { /* ... */ }
}
public class ResourceManager : IDisposable {
public Resource Load() { /* create resource and add to list */ }
public void Dispose()...