If you have 3 classes, with arrows going from parent to child classes (i.e. "A -> B" means "B inherits from A":
shape -> 2d shape -> circle
+----> 3d shape -> sphere
When you write your constructor for the circle class, would you ever just initialize the grandparent Shape object and then your current object, skipping the middle cla...
Hello,
I have a question regarding the C++ Standard.
Suppose you have a base class with user defined copy constructor and assignment operator. The derived class uses the implicit one generated by the compiler.
Does copying / assignment of the derived class call the user defined copy constructor / assignment operator? Or do you need to...
g++ allows this construction of an istream_iterator from an ifstream instance:
std::ifstream ifstr("test.txt");
std::istream_iterator<std::string> iter1(ifstr);
...but it doesn't allow the same construction with an unnamed temporary:
std::istream_iterator<std::string> iter2(std::ifstream("test.txt"));
This gives:
error: no mat...
Hello,
I have declared my own type:
data Book = Bookinfo {
bookId :: Int,
title :: String
} deriving(Show)
and now:
x = Bookinfo
it is all ok, valid statement
but making bookId x throws an error.
If I would be able to handle errors in Haskell that would be ok but right now I cant do this So ...
I have a level class and a Enemy_control class that is based off an vector that takes in Enemys as values.
in my level constructor I have:
Enemy tmp( 1200 );
enemys.Add_enemy( tmp ); // this adds tmp to the vector in Enemy_control
enemys being a variable of type Enemy_control. My program crashes after these statements complaining abou...
I have a custom struct :
struct A
{
public int y;
}
a custom class with empty constuctor:
class B
{
public A a;
public B()
{
}
}
and here is the main:
static void Main(string[] args)
{
B b = new B();
b.a.y = 5;//No runtime errors!
Console.WriteLine(b.a.y);
}
When I run the above program, it does ...
Why constructor is not considered as member of a class ?
Is there any specific reason ?
Thanks and regards.
...
Hi
in this question:
http://stackoverflow.com/questions/2779155/template-point2-double-point3-double
Dennis and Michael noticed the unreasonable foolishly implemented constructor.
They were right, I didn't consider this at that moment.
But I found out that a constructor does not help very much for a template class like this one, instead ...
How can I initilise a structure in the constructor list?
Say:
struct St{int x, y};
class Foo
{
public:
Foo(int a = 0, int b = 0) : /*here initilise st_foo out of a and b*/
{}
private:
const St st_foo;
};
...
Possible Duplicate:
Best Practice: Initialize class fields in constructor or at declaration?
So its monday and we are arguing about coding practises. The examples here are a litttle too simple, but the real deal has several constructors. In order to initialise the simple values (eg dates to their min value) I have moved the co...
I narrowed the causes of an AS3 compiler error 1119 down to code that looks similar to this:
var test_inst:Number = 2.953;
trace(test_inst);
trace(test_inst.constructor);
I get the error "1119: Access of possibly undefined property constructor through a reference with static type Number."
Now if I omit the variable's type, I don't ge...
C# static constructor and GetVersion() any suggestions?
Hi,
I have defined struct like this in separate file OSVERSIONINFO.cs like this:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
public struct OSVERSIONINFO
{
public static int SizeOf
{
get
{
return Marshal.SizeOf (typeof(OSVERS...
I have set up a class to validate credit card numbers. The credit card type and number are selected on a form in a separate class. I'm trying to figure out how to get the credit card type and number that are selected in the other class (frmPayment) in to my credit card class algorithm:
public enum CardType
{
MasterCard, Visa, Amer...
Can a constructor be private? How is a private constructor useful?
...
If I want to create my own class MyWidget which inherits from QWidget
Tutorial tells me to write constructor like this...
MyWidget::MyWidget(QWidget *parent)
: QWidget(parent){....}
I'm wondering what is the role of : QWidget(parent)
Does it mean explicit call for QWidget's constructor?
...
After I decided to implement my Int128 in C#, I thought it would be nice to make it look like other dotNet data types.. But I could not implement the following feature:
suffix initialization: such as 13L and 0.2D
Can I make my own suffix in C#?
And if I can not.. how can I initialize it?
i.e
Int128 a= ??
...
Why does
class A;
template<typename T> class B
{
private:
A* a;
public:
B();
};
class A : public B<int>
{
private:
friend B<int>::B<int>();
int x;
};
template<typename T>
B<T>::B()
{
a = new A;
a->x = 5;
}
int main() { return 0; }
result in
../src/main.cpp:15: error: invalid use of constructor ...
Hello,
I'm using StructureMap for my DI. Imagine I have a class that takes 1 argument like:
public class ProductProvider : IProductProvider
{
public ProductProvider(string connectionString)
{
....
}
}
I need to specify the "connectionString at run-time when I get an instance of IProductProvider.
I have conf...
I was reading some boost code, and came across this:
inline sparse_vector &assign_temporary(sparse_vector &v) {
swap(v);
return *this;
}
template<class AE>
inline sparse_vector &operator=(const sparse_vector<AE> &ae) {
self_type temporary(ae);
return assign_temporary(temporary);
}
It seems to be mapping...
I'm working through this tutorial:
http://www.killerphp.com/tutorials/object-oriented-php/php-objects-page-3.php
At first he has you create a setter and getter method in the class:
<?php
class person{
var $name;
function set_name($new_name){
$this->name=$new_name;
}
function get_name(){
return $...