class-constructors

Populate Property Object during Property Call

Hello all, I'd like to know whether this approach is correct or if their are better ways of doing this. I have what is basically a Person class which has a number of other classes as variables, each of the custom classes is instantiated by passing the Person ID and then that class retrieves the data it needs using that ID. I expose the ...

Responding to application-killing events during class initialization

Hello, When starting my application, I have a couple of classes which are required to read certain files in order to create a set of default data. The logical place (to me) to do this is in a Shared class constructor; the idea would be to throw a class-level event if the reading of the defaults file fails. Unfortunately, this does not ...

Returning in a static initializer

Hello, This isn't valid code: public class MyClass { private static boolean yesNo = false; static { if (yesNo) { System.out.println("Yes"); return; // The return statement is the problem } System.exit(0); } } This is a stupid example, but in a static class const...

Why am I forced to reference types in unused constructors?

Let's say that I have a class (ClassA) containing one method which calls the constructor of another class, like this: public class ClassA { public void CallClassBConstructor() { using(ClassB myB = new ClassB()) {...} } } The class ClassB looks like this: public class ClassB : IDisposable { public ClassB(){} ...

Problems in initializing member of a template class

My code does not compile. Below is my code template <typename T> class TemplateClass { const T constMember; public: TemplateClass() { constMember = T(); } }; int main() { TemplateClass <int> obj; } I get this error : error: uninitialized member 'TemplateClass<int>::constMember' with 'const' type 'c...