virtual

Virtual method causes compilation error in Derived class

时光毁灭记忆、已成空白 提交于 2019-12-12 22:06:19
问题 Consider the next code : #include <iostream> using namespace std; class A { public: virtual int f() {cout <<"A:: f()\n"; return 1;} virtual void f(int) {cout <<"A:: f(int)\n";} virtual void g() {cout <<"A::g()\n";} }; class B3 : public A { public: void f() {cout <<"B3::f ()\n";} }; int main() { return 0; } It produces the following error : ..\main.cpp:17: error: conflicting return type specified for 'virtual void B3::f()' ..\main.cpp:9: error: overriding 'virtual int A::f()' but why ? in the

vtable in case of virtual inheritance [duplicate]

徘徊边缘 提交于 2019-12-12 21:03:58
问题 This question already has answers here : What is Vtable in C++ [duplicate] (3 answers) Why do we need virtual table? (5 answers) How are virtual functions and vtable implemented? (12 answers) Closed 2 years ago . What is the use of vtable (or why is vtable required ) in case of virtual inheritance ? what does this vtable points to in this case. example: class A { void show() { } }; class B : virtual A { void disp() { } }; In the above example the size of class B is 8 bytes. which means class

C++ multiple inheritance off identically named operator

别等时光非礼了梦想. 提交于 2019-12-12 13:33:23
问题 Is it possible to inherit identically named operator which only differ in return type, from two different abstract classes. If so, them: what is the syntax for implementing operators what is the syntax for using/resolving operators what is the overhead in general case, same as for any other virtual function? if you can provide me with a reference or sample code that would be helpful thanks 12struct abstract_matrix { 13 virtual double& operator()(int i, int j); 14}; 15 16 struct abstract_block

C++: Union containing class instances calls wrong virtual function

对着背影说爱祢 提交于 2019-12-12 12:09:51
问题 I came across a strange phenomena upon running the following code: #include <iostream> class Piece { public: class Queen; class Knight; union Any; virtual const char* name() const = 0; }; class Piece::Queen : public Piece { public: virtual const char* name() const { return "Queen"; } }; class Piece::Knight : public Piece { public: virtual const char* name() const { return "Knight"; } }; union Piece::Any { public: Any() {} Piece::Queen queen; Piece::Knight knight; }; using namespace std; int

Rails: Virtual attributes and form values

纵饮孤独 提交于 2019-12-12 11:13:42
问题 I have a Model Book with a virtual attribute for create a Editor from the Book form. The code looks like: class Book < ActiveRecord::Base has_many :book_under_tags has_many :tags, :through => :book_under_tags has_one :editorial has_many :written_by has_many :authors, :through => :written_by def editorial_string self.editorial.name unless editorial.nil? "" end def editorial_string=(input) self.editorial = Editorial.find_or_create_by_name(input) end end And the new form: <% form_for(@book,

Should methods that implement pure virtual methods of an interface class be declared virtual as well?

这一生的挚爱 提交于 2019-12-12 10:37:09
问题 I read different opinions about this question. Let's say I have an interface class with a bunch of pure virtual methods. I implement those methods in a class that implements the interface and I do not expect to derive from the implementation. Is there a need for declaring the methods in the implementation as virtual as well? If yes, why? 回答1: No - every function method declared virtual in the base class will be virtual in all derived classes. But good coding practices are telling to declare

C++ base class function call from last derived in diamond design

人盡茶涼 提交于 2019-12-12 06:09:56
问题 I'm learning C++ and after having read and tested a lot about multiple inheritance, virtual inheritance/methods and diamond design I still have some problems to understand it till the end. I'm in the diamond design pattern, where class B e C inherit virtual public A and D inherits public B, public C : A / \ B C \ / D All classes implement a private variable std::string _message that I initialize with the following string. "class-name instance" Only Class A implements a virtual public display

qt crash internal-error: virtual memory exhausted: can't allocate 32768 bytes

时光总嘲笑我的痴心妄想 提交于 2019-12-12 02:49:35
问题 Using qt 4.8 on windows Application is crashing randomly and rarely once a day It is not breaking in attached debugger and not not showing any code also.. i checked debugger log which says ~"utils.c:1401: internal-error: virtual memory exhausted: can't allocate 32768 bytes.\nA problem internal to GDB has been detected,\nfurther debugging may prove unreliable.\nCreate a core file of GDB? " ~"(y or n) [answered Y; input not from terminal]\n" ~"utils.c:1401: internal-error: virtual memory

Case Study: Polymorphism for Image Processing

ⅰ亾dé卋堺 提交于 2019-12-12 02:43:39
问题 I'm studying Digital Image Processing by myself and would be really grateful if somebody could comment whether polymorphism should be applied for this case or if there's a better class design. Basically, a 2D Filter/Kernel can be either: non-separable or separable . An important kernel operation is the convolution and the way to compute it, depends on the filter type. template < typename T > class CKernel2D{ public: //.... virtual CMatrix<T> myConvolution(const CMatrix<T> & input) = 0; //....

GDB CallStack Address virtual or physical?

。_饼干妹妹 提交于 2019-12-12 01:38:13
问题 My gdb bt callstack gives function name with function address. Then I did nm binary and generated the function name and address mapping. When I tried to match gdb address with nm output it did not match. The function address in (gdb) bt where too high (looks like physical address). gdb function address (e.g 0x00007fffe6fc150f ): #9 0x00007fffe6fc150f in read_alias_file (fname=<value optimized out>, fname_len=<value optimized out>) at localealias.c:224 #10 0x00007fffe6fc1a4e in _nl_expand