I just ran into an awkward issue that has an easy fix, but not one that I enjoy doing. In my class's constructor I'm initializing the data members of a data member. Here is some code:
class Button {
private:
// The attributes of the button
SDL_Rect box;
// The part of the button sprite sheet that will be shown
SDL_Rect*...
In the MIDP api there is a public abstract class Layer, this class has a javadoc published however it doesn't show a constructor in the javadoc.
In the same api there are two other classes Sprite and TiledLayer.
public class Sprite extends Layer
public class TiledLayer extends Layer
All these classes are in the package javax.microed...
Please can anyone tell me what is the error in the following piece of code?
Question is
Create a class person which has
A variable ‘name’ which stores the name of the person.
A constructor that takes a single argument that is used to initialize the name variable
A method getName() which displays the name.
A protected method setName()...
I'm new to IOC containers and learning Ninject. I've using version 2.0, freshly downloaded from Github.
I'm trying to set a string parameter on a constructor when a default constructor is also present. I've been stepping through the Ninject source but I'm insufficiently familiar with the patterns being used to easily pinpoint what I...
New to Ruby, and I'm trying to figure out what idiom to use to restrict some integer values to the constructor of a class.
From what I've done so far, if I raise an exception in initialize(), the object is still created but will be in an invalid state (for example, some nil values in instance variables). I can't quite see how I'm suppo...
Suppose I have the following (simplified case):
class Color;
class IColor
{
public:
virtual Color getValue(const float u, const float v) const = 0;
};
class Color : public IColor
{
public:
float r,g,b;
Color(float ar, float ag, float ab) : r(ar), g(ag), b(ab) {}
Color getValue(const float u, const float v) const
...
I have two classes. SpeciesReader takes files and parses them. Species stores certain data about a species, which has been parsed from the file.
Currently, I have a method: SpeciesReader.generateSpecies(), which uses the file with which it was instantiated to create a Species object. Is this bad practice/design? Should I somehow find a ...
By instantiating an object in C++ with the following class I get a segmentation fault or aborts, depending on the order declaring member variables. E. g. putting mMemberVar and mAnotherMemberVar after mAnotherCountVar results in a segfault. From this listing I removed a std::ofstream from the member variables, which caused the segmentati...
lo.
first time posting on stack.
im trying too just do some past exam questions but its proving difficult so sorry if this sounds noobish.
i need too pass a 1d array that isnt defined in a method.
i need too create a testclass then make the arrays myself.
im just not sure about the syntax.
example
heres my company class
public clas...
Hi, I'd like to be able to initialize a derived class from a base class, like so:
class X {
public:
X() : m(3) {}
int m;
};
class Y : public X {
public:
Y() {}
Y(const & X a) : X(a) {}
};
Is there anything dangerous or unusual by doing that? I want it because I'm deserializing a bunch of objects who's type I don't...
I have a large set classes which I need to "wrap" in a very thin subclass. The functionality of the base classes doesn't change, and their interface remains intact.
The problem is, that in order to use the base classes's constructors (and most of them have more than one), I need to decalre an identical constructor in each of the subclas...
I've been working in .NET for some time now, but occasionally I still get confused by a disparity between the framework and my prior experience in C++.
In .NET, all objects are either value types or reference types. Reference types are allocated on the heap while value types are allocated on the stack (in the current CLR implementation,...
Which of these 3 is the fastest (least CPU cycles) on the AVM2 in ActionScript 3?
Object(instance).constructor
(instance as Object).constructor
instance["constructor"]
I would do some tests, but I have no idea how to accurately profile that kind of thing.
...
How to create some class from dll(constructor in dll)?(с++)
or how to dynamically load class from dll?
...
I have the following code which doesn't compile. The compiler error is:
"error: no matching function to call B::B(B)",
candidates are B::B(B&) B::B(int)"
The code compiles under either of the following two conditions:
Uncommenting the function B(const B&)
change 'main' to the following
int main()
{
A a;
B b0;
...
Consider
Class A has two constructors new A(int), new A(int, String)
also
it has a method show()
Then given a statement like,
A a1= new A(4);
A a2= new A(3, "foo");
and later in code (or in some methods where these object were passed)
a1.show();
a2.show();
new A(3).show();
and
new A(2,"bar").show();
If I wanted to differen...
Hi,
I wanted to What is the Job of Compiler Supplied Constructor ?. Is that constructor does memory allocation and all the stuffs required to create an object.
I am not asking this question from member variable initialization point of view. I want to know what happens inside the code of default constructor that compiler executes and su...
I'm trying to build a class which will initalise its self either by passing in a reference to a record in a database (with the intention that a query will be run against the database and the returned values for the objects properties will be set therein), or by specifying the values "by hand" - this no database call is required.
I've lo...
I'm reviewing some code and I'm seeing a lot of this:
class Foo
{
public:
Foo()
{
// 'nuffin
}
void init()
{
// actual construction code
}
} ;
The only advantage I can see is if you create a Foo without using a pointer and you want to hold off its construction code until later, then you can.
Is this a good idea o...
Let's say I have a class:
class Aggregate {
public:
int x;
int y;
};
I know how to initialize an object using curly braces:
Aggregate a1 = { 1500, 2900 };
But I can't find a proper syntax to create temporary object and pass it as an argument to some method, for example:
void frobnicate(const Aggregate& arg) {
// do...