Ok... in C++ you can new up a subclass from a static method in the base class with 'new this()' because in a static method, 'this' refers to the class, not the instance. That was a pretty damn cool find when I first found it and I've used it often.
However, in C# that doesn't work. Damn!
So... anyone know how I can 'new' up a subclass...
In C++,
Aside from dynamic memory allocation, is there a functional difference between the following two lines of code:
Time t (12, 0, 0); //t is a Time object
Time* t = new Time(12, 0, 0);//t is a pointer to a dynamically allocated Time object
I am assuming of course that a Time(int, int, int) ctor has been defined. I also realize ...
This compiles without error on Scala 2.8.0 final:
import javax.swing.tree.TreePath
object A extends Application {
val path1 = new TreePath()
val path2 = new TreePath(path1, "foo")
}
However, on execution I get:
java.lang.IllegalAccessError: tried to access method javax.swing.tree.TreePath.<init>()V from class A$
at A$.<init>...
homework help time!
I am taking a quadratic expression, where y=ax^2 + bx + c with a,b,c are constants and x is a variable. Here is my class:
class quadratic {
public:
double evaluate(const double x);
void getCoefficients (double &A, double &B, double &C);
void setCoefficients (const double A, const double B, const double C);
private:...
Possible Duplicate:
Is there any danger in calling free() or delete instead of delete[]?
I was reading this question:
http://stackoverflow.com/questions/184537/in-what-cases-do-i-use-malloc-vs-new/
Someone raised that one reason to use malloc was if you were going to use free.
I was wondering: Is it valid to mix a free call ...
Hello,
how can I datatemplate a UserControl with a ViewModel with a NON-Empty constructor ?
public PersonViewModel(Person person)
{
_person= person;
// do some stuff
}
Binding this in Xaml will crash as the Ctor is not empty. But as I use parent/child relations with the ViewModels I have to p...
Ok, I am working on an assignment for school, and I set up my main class and also another class called Transaction. In my main class I have:
Transaction t = new Transaction();
And Transaction is underlined: it says that the constructor undefined. WHY?!
The Transaction class looks like this:
public class Transaction {
private String...
Hi!
I'm developing a c++ application with Xcode 3.1.4
while debugging, if i step into a constructor, i see only the membervariables, but no locals used in the constructor.
does anyone know that problem and how to solve it?
...
I'm trying to import a set of coordinates from an external javascript.
I have to include about 78.740 elements in the constructor, but firefox just throws an error:
"too many constructor arguments"
Does anybody have any ideas?
This is my code:
function CreateArray() {
return new Array(
...
...
...
78.740 elements later
...
); }
...
Hi,
I have a model like this:
class Person(models.Model,Subject):
name = ..
The class Subject is not supposed to be in the Database so, it doesn't extends from models.Model:
class Subject:
def __init__(self,**kargs):
_observers = []
my problem is that the constructor of Subject is never called, so i've tried adding ...
struct Base{
Base(Base &){} // suppress default constructor
};
struct Derived : Base{
};
int main(){
Derived d;
}
The code shown gives error because the default constructor (implicit) of 'Base' is suppressed. Indeed the standard says in $12.1 "If there is no user-declared constructor for class X, a default constructor ...
I write a URL router in Python 3.1 and wonder whether it is more than a matter of taste to use one of the following variants:
Tuples as constructor params:
router = Router(
(r"/item/{id}", ItemResource()),
(r"/article/{title}", ArticleResource())
)
Method calls
router = Router()
router.connect(r"/item/{id}", ItemResource())...
If I have a class A with only a copy constructor and a constructor with parameters int and int, and I place that class inside a class B:
class B
{
public:
B();
private
A a;
}
How would I initialize a inside B's constructor?
I've tried a(0, 0), a = A(0, 0), but not surprisingly neither worked, and I receive a
error: no match...
Hi,
The following code doesn't work:
class String{
public:
char* str;
int* counter;
String(){
str = NULL;
counter = new int;
*counter = 1;
};
String(const char* str1){
String();
str = new char[strlen(str1)+1];
strcpy(str, str1);
};
};
I've changed the call to...
Right now I have a class A that inherits from class B, and B does not have a default constructor. I am trying the create a constructor for A that has the exact same parameters for B's constructor, but I get:
error: no matching function for call to ‘B::B()’
note: candidates are: B::B(int)
How would I fix this error?
...
After reading this thread
http://stackoverflow.com/questions/121162/what-does-the-explicit-keyword-in-c-mean
I made up this program
class MyClass
{
public:
explicit MyClass(int a)
{
cout<<"Int was called"<<endl;
val = a;
}
MyClass(char *a)
{
cout<<"Char was called"<<endl;
val = atoi(a);
}
MyClass(const...
I have a constructor that need to validate passed data.
public Rational(int m, int n)
If n == 0 i should inform user about that.
I know 3 ways to do that.
1) Just make return; in coustructor
2) Generate an exception
3) Create a static method that will create an object
r = new Rational();
r = Rational.GetObject(1,2);
What is the be...
Hello guys,
I'm producing very code using Identities Project to represent the objects, but it is some 1000 entities, and i need to know if exists some plugin or something .net free than produces auto contructor to each instance based on class fields.
Example
class Thing {
public readonly string a;
public readonly Object b;
}
// ...
Hi
I'm sure I've seen somewhere that I can do the following by using an attribute above my Init() method, that tells the compiler that the Init() method must only be called from the constructor, thus allowing the readonly field to be set. I forgot what the attribute is called though, and I can't seem to find it on google.
public class ...
Hello SO,
I am a bit ashamed to ask that, being a Java programmer for years, but here goes:
Is there a difference between allocating objects during construction, and doing so directly when declaring the relevant field? That is, is there a difference between the following two:
public class MyClass{
MyObj obj=new MyObj();
}
AND
pu...