Say I am declaring a class C and a few of the declarations are very similar. I'd like to use a function f to reduce code repetition for these declarations. It's possible to just declare and use f as usual:
>>> class C(object):
... def f(num):
... return '<' + str(num) + '>'
... v = f(9)
... w = f(42)
...
>>> C.v...
I've seen this syntax a couple times now, and it is beginning to worry me:
for example:
iCalendar iCal = new iCalendar();
Event evt = iCal.Create<Event>();
Google can't help, but I know SO can!
...
I have a class that only really ever needed by classes in a certain class hierarchy. I wanted to know if it is possible to nest the class in the highest class's protected section and have all the other classes automatically inherit it?
...
I was thinking along the lines of using typeid() but I don't know how to ask if that type is a subclass of another class (which, by the way, is abstract)
Edit: I should definitely mention the language, C++
...
Ok,
So, I have a class library with all my database logic. My DAL/BLL.
I have a few web projects which will use the same database and classes, so I thought it was a good idea to abstract the Data Layer into its own project.
However, when it comes to adding functionality to classes for certain projects I want to to add method to cer...
I am trying to declare and use a class B inside of a class A
and define B outside A.
I know for a fact that this is possible because Bjarne Stroustrup
uses this in his book "The C++ programming language"
(page 293,for example the String and Srep classes).
So this is my minimal piece of code that causes problems
class A{
struct B; // fo...
We recently had a code review . One of my classes was used so that I could return/pass more than one type of data from/to methods . The only methods that the class had were getters/setters . One of the team's members ( whose opinion I respect ) said that having a class like that is bad practice ( and not very OOP ) . Why is that ?
...
I write a Text Editor with Java , and I want to add Undo function to it
but without UndoManager Class , I need to use a Data Structure like Stack or LinkedList but the Stack class in Java use Object parameters e.g : push(Object o) , Not Push(String s)
I need some hints or links .
Thanks
...
What is the Constant Value of the Underline font in Java ?
Font.BOLD bold font
Font.ITALIC italic font
What is the UNDERLINE font Constant ?
I try all the available constants but it didn't work .
...
With a class in python, how do i define a function to print every single instance of the class in a format defined in the function.
...
I'll phrase this in the form of an example to make it more clear.
Say I have a vector of animals and I want to go through the array and see if the elements are either dogs or cats?
class Dog: public Animal{/*...*/};
class Cat: public Animal{/*...*/};
int main()
{
vector<Animal*> stuff;
//cramming the dogs and cats in...
for(/*all ele...
I'm calling this linear class relationship, but correct me if I'm wrong. I'm looking to test whether or not the class of object A is an ancestor or descendant of object B's class.
For example, AbstractCollection is linearly related to both Object and ArrayList. However, ArrayList is not linearly related to Vector.
My first stab was:
/...
I've got the following generic class and the compiler complains that "Operator '!=' cannot be applied to operands of type 'TValue' and 'TValue'" (see CS0019):
public class Example<TValue>
{
private TValue _value;
public TValue Value
{
get { return _value; }
set
{
if (_value != value) // <<...
To me at least, the Pair class is a very multi-purpose class. So why did Microsoft put it into the System.Web.UI namespace?
Is there a reason that my tiny brain cannot comprehend?
Thanks.
...
Sorry for the bad title, but I couldn't think of a better one.
I'm having a class A and a class B which is kind of a sub class of A, like so:
(Is there actually a correct name for it? Isn't "sub class" reserved for inheritance?)
class A {
int i = 0;
class B {
int j = 1;
}
}
class Test {
public static void main...
What are the C++ coding and file organization guidelines you suggest for people who have to deal with lots of interdependent classes spread over several source and header files?
I have this situation in my project and solving class definition related errors crossing over several header files has become quite a headache.
...
I'm looking for a free templating engine to generate simple reports. I want some basic features such as :
Ability to Write Loops (with any IEnumerable)
Passing Variables
Passing Templates Files (main template, footer, header)
I'll use this to generate reports in HTML and XML. I'm not looking for a ASP.NET Template Engine.
This is fo...
I am making a game in JAVA where I want to come up with a list of files in a certain directory in my jar so I can make sure to have a list of those classes to be used in the game.
For example say in my jar I have a directory
mtd/entity/creep/
I want to get a list of all the .class files in that directory using java code from another...
I've been using moq to mock objects in my unit tests and I've seen on the site about moq that it is able to mock both classes and interfaces.
I had a discussion with one of my work mates the other day and they stated that there is never a reason to mock classes and I should only mock interfaces.
I didn't really have an answer to that.....
Recently I used a class that inherits from a collection instead of having the collection instantiated within the class, is this acceptable or does it create unseen problems further down the road? Examples below for the sake of clarity:
public class Cars : List<aCar>
instead of something like:
public class Cars
{
List<aCar> CarList =...