Max
didn't get your question about color
Max
explain more
Anonymous
didn't get your question about color
1984 year is dog sign color is= green 1996 year is dog but color is yellow
Like glm::matrix?
Like matrix operations in fortran
Anonymous
Japanese zodiac calendar
Max
every 12 years new color?
Max
how many colors?
Anonymous
5 colors
Max
(year / 12) % 5
Anonymous
(year / 12) % 5
Can u explain more
Max
well, you said that every 12 years there is a new color
Max
so to get how many 12-years peroids was already passed, you need to divide year by 12
Max
right?
Anonymous
Thanks i undo
Max
em, what? :D
Max
your 1st switch is right, all you need is to write one more switch
Max
to display color
Anonymous
Ok but how can u send me i example
Max
switch ((year / 12) % 5) { case 0: std::cout << "Green"; break; /* and so on */ }
Anonymous
Bro
Max
Bro
np, enjoy :)
Anonymous
Massive in c++ in python is like list
Anonymous
?
Max
what?
Anonymous
what?
[ ] what is that in cpp
AndrEEa
add
in the inerhit class?
AndrEEa
can you explain me better please?
Max
[ ] what is that in cpp
std::list, std::array, std::vector
Max
can you explain me better please?
let me finish my lunch, I'll give you some ideas :D
AndrEEa
ok thanks a lot
Max
ok thanks a lot
struct base { base() = delete; virtual void foo() { throw "Not impl!"; } virtual void foo(int &err) { throw "Not impl!"; } }; struct derived : base { void foo() override { /* some custom implementation */ } }; /* main */ base *b = new derived; /* or get it from somewhere */ b->foo(); /* OK */ int err; b->foo(err); /* Throws */
AndrEEa
thanks a lot
Max
enjoy :)
AndrEEa
btw I don't use pointer if I can
AndrEEa
base b;
Max
why then you need an inheritance?
Max
I asked it wrong, sorry. Why do you need virtual methods if you not going to use a dynamic polymorphism?
Francesco
If you use a method override in the class derivate you have the derivate function
Max
yea, that's why I post that code to @Andrea993
Francesco
You don't need to use pointers btw
Max
or your reply directed not to me?
Max
btw ❤️ ArchLinux
Max
nope you can't ;)
AndrEEa
archlinux❤️ +1
Francesco
or your reply directed not to me?
No, i use your code for answare @Andrea993....btw max payne ❤️❤️❤️❤️❤️❤️
Max
^_^ I love this game too
Max
btw, I did mistake there
Max
ctor of base class should be protected
Max
in order to let derived class instatiate base subobject. so, correct one is: struct base { virtual void foo() { throw "Not impl!"; } virtual void foo(int &err) { throw "Not impl!"; } protected: base() { } }; struct derived : base { void foo() override { /* some custom implementation */ } };
Francesco
btw, I did mistake there
no, you have no make mistake. But you can also write base b = derivate();
Francesco
Francesco
this is what i mean (sorry for the poor example)
Francesco
it won't compile with deleted base ctor
ah sorry, you're right. I didn't read that part
Francesco
i skip some message sorry max :-P
Max
no problem :)
Max
this is what i mean (sorry for the poor example)
yes, indeed I checked and compiler generates copy constructor/assignment operator for me. but, it is kinda meaningless. #include <iostream> struct base { virtual void foo() { throw "Not impl!"; } virtual void foo(int &err) { throw "Not impl!"; } protected: base() { } }; struct derived : base { void foo() override { /* some custom implementation */ std::cout << "derived" << std::endl; } int a; int b; }; int main() { derived d; base c = d; c.foo(); return 0; }
Max
> ./a.out terminate called after throwing an instance of 'char const*' fish: “./a.out” terminated by signal SIGABRT (Abort)
Max
actually, copy constructor must be deleted too
Max
good that we've find out what happens. I always thought that compiler won't let me assign objects directly :)
Max
(in the same hierarchy)
Anonymous
i want for example virtual int fun() = 0; virtual int fun(int &errorecode) = 0; and who implements the class should be able to choose if he wants errcode or not
The problem is, inheritance should not ne used here. When using public inheritance, make sure there is a "is-a" relationship between base and derived class
Liam
suppose that derived class does not implement fun(int &errorcode), and user calls p->foo(err) what should happen?
Acturally, if fun(int& errorcode) is marked pure virtual, say = 0, and in a derived class this function member is not implemented, the derived class cannot be instantiation. That is, Derived d; will raise a compile error. MWE goes here: class Base { public: virtual bool func() const = 0; virtual bool func(int input) const = 0; public: virtual ~Base() {} }; class Derived : public Base { public: bool func() const override { return true; } }; int main() { Derived d; return 0; }
Liam
i want for example virtual int fun() = 0; virtual int fun(int &errorecode) = 0; and who implements the class should be able to choose if he wants errcode or not
I see no difference between the dynamic binding of normal function members and function members who are overloaded. Actually, in C++, after compile, overloaded functions have different name (symbol name). Taking the following codes as an example: #include <iostream> class Base { public: virtual bool func() const = 0; virtual bool func(int input) const = 0; public: virtual ~Base() {} }; class Derived : public Base { public: bool func() const override { std::cout << "func without any prarmeter is called." << std::endl; return true; } bool func(int input) const override { std::cout << "func without an integer as parameter is called " << "and the input is " << input << "." << std::endl; return true; } }; int main() { Derived d; Base* p = &d; p->func(); p->func(42); return 0; } If you compile it and run it, you'll get the result: func without any prarmeter is called. func without an integer as parameter is called and the input is 42. Which means that dynamic binding works just fine. Now have a look at its symbol list.
Liam
Symbols in `pure-virtual.o`.
Liam
You can find that, the overloaded function members, say Derived::func() const and Derived::func(int) const do not share the same symbol name. Hence, in the view of linker ( ld for example), they are just two different functions.
Liam
In this example, A b = B(); will crop anything in the derived class B but not in the base class A. If you want polymorphic, use pointers or references.
Liam
> ./a.out terminate called after throwing an instance of 'char const*' fish: “./a.out” terminated by signal SIGABRT (Abort)
In base c = d;, anything in derived but not in base is cropped, as stated above. Hence, in c, there is no int a; and int b;, also, the function foo stays throw "Not impl!";. There is no need to implement foo s in base class as throw "Not impl!";. In this situation, base class is regraded as an interface, which means that interface classes cannot be instantiated. Copy or move constructors and assignment operators are meanless for a class which cannot be instantiated. Just use pure virtual functions, say = 0, in interface classes.