OK I am not a very experienced C++ programmer, but I was wondering what is the significance of the underscores in the arguments of the following constructor?
class floatCoords
{
public:
floatCoords(float _x, float _y, float _width, float _height)
: x(_x), y(_y), width(_width), height(_height)
{
}
float x, y, width, heigh...
I have a class like below:
class Foo
{
public Foo(int x) { ... }
}
and I need to pass to a certain method a delegate like this:
delegate Foo FooGenerator(int x);
Is it possible to pass the constructor directly as a FooGenerator value, without having to type:
delegate(int x) { return new Foo(x); }
?
EDIT: For my personal use, ...
Vector(const Vector& other) // Copy constructor
{
x = other.x;
y = other.y;
Why is the argument a const?
...
I have a class in PHP like so:
class ParentClass {
function __construct($arg) {
// Initialize a/some variable(s) based on $arg
}
}
It has a child class, as such:
class ChildClass extends ParentClass {
function __construct($arg) {
// Let the parent handle construction.
parent::__construct($arg); ...
In JavaScript, I want to create an object instance (via the new operator), but pass an arbitrary number of arguments to the constructor. Is this possible?
What I want to do is something like this (but the code below does not work):
function Something(){
// init stuff
}
function createSomething(){
return new Something.apply(null...
In C code like such:
{
int i = 5;
/* ....... */
}
The compiler will replace the code by moving the Stack pointer down (for stacks growing down) by the size of an int, and places the value 5 in that memory place.
Similarly, in C++ code, what does the compiler do if an object is created? For example:
class b
{
public :
...
I'm reading Programming Perl, and I found this code snippet:
sub new {
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = {
color => "bay",
legs => 4,
owner => undef,
@_, # Override previous attributes
};
return bless $self, $class;
}
With...
I would like to have the constructor abort object construction whenever it encounters certain error code (e.g. if the following is encountered):
CudaObj::CudaObj(InsertionSim *theSim)
{
// Setup
if(cublasInit() == CUBLAS_STATUS_NOT_INITIALIZED) {
printf("CUBLAS init error.\n");
return -1; // abort here rather than ret...
I discovered that an event raised (directly on indirectly) in the constructor cannot be handled outside the very class. To prove if that was the actual problem, I wrote a simple exemplary app.
Class with the event:
Namespace Utils
Public Class A
Public Event Test()
Public Sub New()
CallTest()
En...
I'm aware of this question, but the asker seems to have been content with an answer to another question (how to overload the constructor)
I have a class which kind of acts as an advanced memoizer around a mutable class, so that I can treat it as immutable from outside:
type Wrapper(args) =
let tool = new MutableTool()
tool.Init...
I've got a server control that contains nested server controls,
<uc1:ArticleControl runat="server">
<HeadLine></HeadLine>
<Blurb></Blurb>
<Body></Body>
</uc1:ArticleControl>
Code:
[ToolboxData("<{0}:ArticleControl runat=server></{0}:ArticleControl>")]
[ParseChildren(ChildrenAsProperties = true)]
public class ArticleCon...
Hi,
I can't decide which approach is better for creating objects with a large number of fields (10+) (all mandatory) the constructor approach of the getter/setter. Constructor at least you enforce that all the fields are set. Java Beans easier to see which variables are being set instead of a huge list.
The builder pattern DOES NOT seem ...
Hello,
I am following up on this question, 1268817
In the question, we find a way to create an isntance of an object given a the name (as a string) of the class.
But what about to create an array of those objects... how would one initialize that.
I was thinking something in the line of but doesnt seem to work
Object[] xyz = Class....
Can I use default arguments in a constructor like this maybe
Soldier(int entyID, int hlth = 100, int exp = 10, string nme) : entityID(entyID = globalID++), health(hlth), experience(exp), name(nme = SelectRandomName(exp))
{ }
I want for example exp = 10 by default but be able to override this value if I supply it in the constructor othe...
I'm working on someone's code and they have a constructor that uses:
class qwerty {
public function __construct(){
// some other code
$this->get = $_GET;
}
}
My question is this: Is it possible to sanitize the data within the constructor?
Even using some simple function like strip_tags()?
Example of usage:
$qwerty = new qwerty;
...
Data class, in this question scope, is a class with more public properties than methods.
Should I:
public class Complex
{
public double Real { get; set; }
public double Imaginary { get; set; }
}
Or:
public class Complex
{
public double Real { get; set; }
public double Imaginary { get; set; }
public Complex(double...
Ok, so I am just starting to use C intrinsics in my code and I have created a class, which simplified looks like this:
class _Vector3D
{
public:
_Vector3D()
{
aVals[0] = _mm_setzero_ps();
aVals[1] = _mm_setzero_ps();
aVals[2] = _mm_setzero_ps();
}
~_Vector3D() {}
private:
__m128 aVals[3];
};
So far so good. But when I create a sec...
Boost deserialization of contained object fails when performed from a constructor, but succeeds otherwise.
E.G.:
ContainingClass::ContainingClass() {
pNA = new objectArray*[NUMBER]; // allocates ptrs
// ...
pNA[ii] = new objectArray(SIZE);// allocates object array, and object array
// has...
If a non-gui object constructor wires a local event handling method to the event field of an object on a different thread, is it possible for said event handling method to be called before the constructor is finished?
Example: (semantic pseudocode only)
public static B b = new B();
class A
{
public A()
{
b.evt += Event...
On Windows, several arguments are passed to the DllMain constructor:
BOOL WINAPI DllMain(
__in HINSTANCE hinstDLL,
__in DWORD fdwReason,
__in LPVOID lpvReserved
);
From hinstDLL I can get the fully qualified file name of the DLL itself using GetModuleFileName():
LPTSTR str = new TCHAR[256];
int libNameLength = GetM...