I have a method foo in class C which either calls foo_1 or foo_2.
This method foo() has to be defined in C because foo() is pure virtual in BaseClass and I actually
have to make objects of type C. Code below:
template <class T>
class C:public BaseClass{
void foo() {
if (something()) foo_1;
else foo_2;
}
void foo_1() {
...
I'm creating a Class.
This class stores user preferences in a Struct.
When creating an instance of the class, I want the client to have the option of creating an instance with no preferences passed in or with a preferences struct passed in.
I can do this with pointers, but I wanted to know how I could do it by passing the preferences...
Can someone point out to me what I'm doing wrong or where my understanding is wrong?
To me, it seems like the code below which instantiates two objects should have separate data for each instantiation.
class Node:
def __init__(self, data = []):
self.data = data
def main():
a = Node()
a.data.append('a-data') #only a...
As we know we can instantiate an object without new keyword by using classloader/object cloning/object serialization. When I am using these techniques to create an object, is the constructor called or not?
...
Hello All,
Does the given code samples perform same operation? Do i really need a EXTRA object instantiation code? Will there be any issue with the first code segment?
Sample 1
Dog adog= new Dog();
adog.ID = dogID;
adog.CategoryId= dogCategoryId;
adog= DogRepository.FindDogByCategoryId(adog);
Assign the values back to the same obje...
I saw some code written by another developer that looks something like this:
var stringBuilder = new StringBuilder();
if(stringBuilder == null)
{
// Log memory allocation error
// ...
return;
}
(It is ALL over the place in the code )
Question 1:
Would that error logging code even get called? If there was no memory, woul...
Hi
I'm trying to create a new Float type with 6 digits precision. But it seems that I'm not able to use it. Here's the code from the package MyFloat_IO.ads
WITH Ada.Text_IO;
PACKAGE MyFloat_IO IS
TYPE MyFloat IS DIGITS 6 RANGE 0.0..Float'Last;
PACKAGE MyFloat_IO IS NEW Ada.Text_IO.Float_IO(MyFloat);
end MyFloat_IO;
and the main ...
I was using newInstance() in a sort-of performance-critical area of my code.
The method signature is:
<T extends SomethingElse> T create(Class<T> clasz)
I pass Something.class as argument, I get an instance of SomethingElse, created with newInstance().
Today I got back to clear this performance TODO from the list, so I ran a couple of...
I have a function that returns a bitmap meant to be used as background in a panel, and occasionally I'd have to call it to create a new background based on parameters.
(Since there are two drawing functions for this panel (the background doesn't need to be changed as often as the foreground) it's not a matter of just drawing on the Pain...
I have a generic method that takes in a type T, which i need to be able to call a constructor on that requires a single XmlNode. Currently, I am trying to do that by having an abstract base class that has the constructors I want (plus a parameterless one so i don't have to edit the "subclasses" other than to add the actual subclassing) a...
In C#/.NET:
I have 2 concrete classes. Class A and B. Class B subclasses from Class A.
How many instances (objects on the heap) and references from the stack to the heap objects are created for each line of code:
ClassB b = new ClassB();
ClassA a = new ClassB();
Thanks!
...
Hi,
I have a requirement to accept an array of checked items from a table and update a field based on which items have been selected. Initially my thoughts where to simply loop over each of these items in the array and access a function in the specific class to update the status.
I'm slightly concerned about this approach as it would m...
I come from a c++ background and I find myself constantly doing this in java:
SomeClass sc=new SomeClass();
if(null!=sc)
{
sc.doSomething();
}
What I want to know is what will be in the variable sc if the constructor fails for some reason (like maybe not enough memory). I can'
t find a straight answer, and I am worried that I am...
I am trying to compile with g++ 4.4 and link a simple program that uses the STL.
I am trying to do it using the -fno-implicit-templates so all templates must be instantiated explicitly.
I don't understand why this code works:
#include <map>
//template class std::map<char,char>;
template class std::_Rb_tree<char, std::pair <char const, ...
I developed a generic "Unsigned" class, or really a class template Unsigned<size_t N> that models after the C (C++) built-in unsigneds using the amount of uint8_ts as a parameter. For example Unsigned<4> is identical to a uint32_t and Unsigned<32> would be identical to a uint256_t -- if it existed.
So far I have managed to follow most i...
Hello,
I'm working on my first iOS app. I haven't had a problem using interface builder in the standard way.
I want to use interface builder to configure and instantiate a button, but not add it to a view (because I want to add the button to a navigation bar, which is created in a different nib).
I tried to simply add the button (a seg...
The problem I am having is I create two different menus from a single class. When I finish the first one, everything is fine. However when I create the second one and set it's region, it modifies the previous one as well. When I call Display() which just flips a boolean variable, it flips it for both instead of just the one I'm calling t...
I have a template class with a template member function. I want to explicitly instantiate the class to avoid a drastic compilation slowdown. I am using g++ 4.1.2. I get ambiguous template specialization errors from the compiler. This the shortest code which will reproduce the problem:
template <class T, class S >
class Test
{
public:
...
<?php
class Student { public $name = "Benjamin"; }
$name = new Student();
?>
<p>Hello, there. My name is <?php $name->name ?></p>
The above code doesn't work as intended (printing the name within "p" tags). But the below code, of course, does work:
<?php
class Student { public $name = "Benjamin"; }
$name = new Student();
echo '<...
I'm trying to use WebORB for PHP.
The /weborb/ folder has been copied into my web root and I can access the console via /weborb/index.php.
I've copied my test application into /weborb/_Services/Test/Main.php. The file contents is as follows:
<?php
require_once '/home/user/www/MyClass.php';
class Main
{
public function testMethod(...