public MyClass(int someUniqueID)
{
using(//Session logic)
{
var databaseVersionOfMyClass = session.CreateCriteria(/*criteria*/)
.UniqueResult<MyClass>();
//Load logic
}
}
The code sample above is my current direction, although I've reached a point where I need a bit of a sanity check.
With NHibernate(I'm gree...
I have a class whose constructor takes a const reference to a string. This string acts as the name of the object and therefore is needed throughout the lifetime of an instance of the class.
Now imagine how one could use this class:
class myclass {
public:
myclass(const std::string& _name) : name(_name) {}
};
myclass* proc() {
...
If I have a class like this:
typedef union { __m128 quad; float numbers[4]; } Data
class foo
{
public:
foo() : m_Data() {}
Data m_Data;
};
and a class like this:
class bar
{
public:
bar() : m_Data() {}
foo m_Data;
}
is foo's constructor called when making an instance of bar?
Because when I try to use bar's m_Data...
Hi,
In ASP.Net, is it possible to pass parameters to the "New" constructor of a User Control class? In VB.Net:
Public Sub New(ByVal pRequiredParam As String)
'Do something with required Param
End Sub
When I use this user control in a generic ASP.Net page, it doesn't prompt me for "pRequiredParam". Of course, if this was a "normal...
Imagine I have a C++ class Foo and a class Bar which has to be created with a constructor in which a Foo pointer is passed, and this pointer is meant to remain immutable in the Bar instance lifecycle. What is the correct way of doing it?
In fact, I thought I could write like the code below but it does not compile..
class Foo;
class ...
In Java, one can create instances of a class without actually calling a declared constructor by retrieving one via sun.reflect.ReflectionFactor.newConstructorForSerialization().
As far as I know, this special constructor is called "munged". Where does this term come from? I could not find it in any dictionary.
...
I read all the questions related to this topic, and they all give reasons why a default constructor on a struct is not available in C#, but I have not yet found anyone who suggests a general course of action when confronted with this situation.
The obvious solution is to simply convert the struct to a class and deal with the consequence...
In my @interface theres a NSArray *Monate followed by:
@property (nonatomic, retain) NSArray* Monate;
If i do:
filePath = [[NSBundle mainBundle] pathForResource:@"SomeFile" ofType:@"plist"];
self.Monate = [NSArray arrayWithContentsOfFile:filePath];
in the constructor, it gets set to an autoreleased object (is that correct?).
So s...
Hello everyone,
I realize this is a pretty open question and could get a variety of answers, but here goes.
Using C# (or Java, or any OO language), is there a general rule that states how many variables should be passed into the constructor? The number of variables I am passing into the constructor of the extended classes seem to be g...
I read about virtual constructors are used for implementing some design patterns, but didn't understood any need of virtual constructors. So what are virtual constructors and why we really need them?
...
I have a cpp file like this:
#include Foo.h;
Foo::Foo(int a, int b=0)
{
this->x = a;
this->y = b;
}
How do I refer to this in Foo.h?
...
I'm loosely following an excellent series of blog posts by Kazi Manzur Rashid as a learning exercise for learning how to implement some new (for me at least) design patterns, but I'm getting trouble from the start.
I've basically copied his code for the Database, RepositoryBase and RepositoryBaseTests classes, but when I try to run the ...
This is pretty basic, but sort of a generic issue so I want to hear what people's thoughts are. I have a situation where I need to take an existing MSI file and update it with a few standard modifications and spit out a new MSI file (duplication of old file with changes).
I started writing this with a few public methods and a basic inpu...
Here is a code I would like to get to work:
template <class A>
class B : public A {
public:
// for a given constructor in A, create constructor with identical parameters,
// call constructor of parent class and do some more stuff
B(...) : A(...) {
// do some more stuff
}
};
Is it possible to achieve behavior described by a...
I have an assignment from my programming class, which is very poorly worded... The following line really stumps me. We're creating a class called FloatArray, which contains an array (arr, which is just a pointer to a bunch of floats).
The default constructor FloatArray(); should create array of zero width and zero height.
I have ...
I whish to define properties in a class from a member function.
Below is some test code showing how I would like this to work. However I don't get the expected behaviour.
class Basket(object):
def __init__(self):
# add all the properties
for p in self.PropNames():
setattr(self, p, property(lambda : p) )
def PropNames...
Given the following class:
public class MyClass
{
private string _param;
public MyClass ()
{
_param = string.Empty;
}
public MyClass (string param)
{
_param = param;
}
}
I am torn apart between two ways to chain those constructors:
The first one:
public MyClass () : this (string.Empty)
{...
Please forgive the length, but here are two programs, both the exact same, but one with and one without setters, getters, and constructors.
I've taken a basic C++ class before and don't remember any of these from it, and at the moment I'm not seeing the point of them, if anyone could explain them in lamen's terms I'd much appreciate it....
I have written the following function that permits creation of singleton classes from given classes:
function SingletonFrom(Constructor) {
return function() {
var self = arguments.callee;
if (self._instance === undefined) {
switch (arguments.length) { // this is ugly
case 0: self._instanc...
I'm working with some existing code, trying to add to it and increase the unit tests for it. But running into some problems with getting the code testable.
Original Constructor:
public Info() throws Exception
{
_ServiceProperties = new ServiceProperties();
_SshProperties = new SshProperties();
}
I'm aware that this is bad, and ob...