There is a member function which I would like to delete the current object and create an array of new ones in its place. How is it possible? The following code is an attempt of mine which has a lot of mistakes.
void LernaeanHydra::split(int parts)
{
LernaeanHydra *new_heads = new LernaeanHydra[parts];
for (int i = 0; i < parts; ...
I know that in C# you can nowadays do:
MyObject a = new MyObject()
{
Property1 = 1,
Property2 = 2
};
Is there something like that in PHP too? Or should I just do it through a constructor or through multiple statements;
$a = new MyObject(1, 2);
$a = new MyObject();
$a->property1 = 1;
$a->property2 = 2;
If it is possible but...
How to stop a static constructor(i.e. module constructor & type constructor) from running in .NET?
For example:
class A
{
static A()
{
Environment.Exit(0);
}
static int i()
{
return 100;
}
}
How to invoke i() without exiting?
...
Hello. I've got a problem with this code:
#include <fstream>
struct A
{
A(std::ifstream input)
{
//some actions
}
};
int main()
{
std::ifstream input("somefile.xxx");
while (input.good())
{
A(input);
}
return 0;
}
G++ outputs me this:
$ g++ file.cpp
file.cpp: In function `int mai...
According to the C++0x spec, the following is legal
class A {
A(int i) : x(i) {}
A() : A(0) {}
int x;
};
But it fails to compile ("A" is not a nonstatic data member or base class of class "A") in VC 2010. Anyone know what's wrong?
...
I have a logic in base class constructor. The result of the logic has to be captured in the derived class constructor in a temporary variable. Is there a way to do it?
For example
class Base
{
Base() { int temp_value = some_logic; }
};
class Derived : public Base
{
Derived() { // need the temp value here.. }
};
Thanks,
Goku...
package pkgPeople;
import java.io.Serializable;
import java.text.DecimalFormat;
public class Person implements Serializable{
private String name;
private int height;
private int weight;
private BankAccount bankAccount;
private static int personCT=0;
private String noAccount;
//The Default constructor, a method
public Person()
{
...
defrecord in clojure allows for defining simple data containers with custom fields.
e.g.
user=> (defrecord Book [author title ISBN])
user.Book
The minimal constructor that results takes only positional arguments with no additional functionality such as defaulting of fields, field validation etc.
user=> (Book. "J.R.R Tolkien" "The L...
Hello, I have an object of class which has private constructor:
class CL_GUIComponent
{
// ...
private:
CL_SharedPtr<CL_GUIComponent_Impl> impl;
CL_GUIComponent(CL_GUIComponent &other);
CL_GUIComponent &operator =(const CL_GUIComponent &other);
CL_GraphicContext dummy_gc;
};
I have a class which has a pointer t...
Okay so I have an assignment where I have to create a class with a set of private properties, which I have done. It gets tricky because I'm fairly new to java programming (or programming in general) and am not very practiced in encapsulation. I have not used getters/setters or constructors before. I understand the getter/setter methods, ...
I have the following Scala class:
class Person(var name : String, var age : Int, var email : String)
I would like to use the Person constructor as a curried function:
def mkPerson = (n : String) => (a : Int) => (e : String) => new Person(n,a,e)
This works, but is there another way to accomplish this? This approach seems a bit tedio...
Id' like to know how to write a constructor for a custom class (a linked list in this case) that accepts any STL input iterator. I have already created a custom Iterator class which is tied to my List class.
This works fine.
template <typename T>
List<T>::List(Iterator beg, Iterator end) : first_(0) {
while (beg != end)
...
So, I've been looking at boost::array but it does require default constructor defined.
I think the best way of filling this array with data, would be through a push_back(const T&) method. Calling it more times than SIZE (known at compile-time) would result in assert or exception, depending on build configuration. This way it would always...
What is the code-snippet or short cut to create a constructor in Visual Studio?
Visual Studio 2010 and C#.
I've used before but I can't remember.
...
Update: gutted the question with a simpler example, that isn't answered
by the originally accepted answer
Given the following class, and its ancestor:
TComputer = class(TObject)
public
constructor Create(Teapot: string='');
end;
TCellPhone = class(TComputer)
public
constructor Create(Cup: Integer); overload; virtual;
co...
I've got a function wich can accept a varible number of parameter with a rest operator.
I want create an object passing the argument collected with the rest operator directly to a constructor without create an object and call an initializing function and without passing the entire array but the parameters ah I do with apply() function...
i'm looking to understand
virtual
override
overload
reintroduce
when applied to object constructors. Every time i randomly add keywords until the compiler shuts up - and (after 12 years of developing with Delphi) i'd rather know what i'm doing, rather than trying things randomly.
Given a hypothetical set of objects:
TComputer = cla...
Update: The example i originally had was kind of complex. Here's a simple 8 line example that explains everything in one code block. The following does not compile gives a warning:
TComputer = class(TObject)
public
constructor Create(Cup: Integer); virtual;
end;
TCellPhone = class(TComputer)
public
constructor Create(Cup: Integ...
A class has a unique constructor taking IMyInterface as its argument. If I define a concrete type of IMyInterface and registers it to StructureMap then there is no issue and my class can be instanciated with this concrete type.
However, in some cases, no concrete type will be registered. In that case, I would like to receive null for th...
Today Recently on Stackoverflow i learned that:
reintroduce is used to hide ancestor constructors
reintroduce is used to show ancestor constructors
i've been trying to make sense of it all, so here is a another, very specific question, supporting my main question dealing with constructors.
Update: replaced the entire question:
TC...