virtual

How to create virtual CAN port on linux? (C++)

跟風遠走 提交于 2019-11-28 20:35:11
问题 I want to create program that would emulate CAN port for testing purposes for another big application. Program should send previously recorded data through this virtual CAN. Anyone has any experience with such thing? I'm thinking to establish virtual COM, and send through it data packed in CAN Frames. Could it work? And how could I establish virtual COM on linux? Found this thread Virtual Serial Port for Linux but sadly I don't get how could it be implemented into source code of program

C# virtual static method

房东的猫 提交于 2019-11-28 19:10:58
Why is static virtual impossible? Is C# dependent or just don't have any sense in the OO world? I know the concept has already been underlined but I did not find a simple answer to the previous question. virtual means the method called will be chosen at run-time, depending on the dynamic type of the object. static means no object is necessary to call the method. How do you propose to do both in the same method? Michael Stum Eric Lippert has a blog post about this, and as usual with his posts, he covers the subject in great depth: http://blogs.msdn.com/b/ericlippert/archive/2007/06/14/calling

How do virtual functions work in C# and Java?

本秂侑毒 提交于 2019-11-28 18:48:48
How do the virtual functions work in C# and Java? Does it use same vtable and vpointer concept similar to C++ or is it something totally different? How do virtual functions work in Java? Coding interviewers love this question. Yes. Although Java does NOT have a virtual keyword, Java has virtual functions and you can write them. In object-oriented programming, a virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature. This concept is a very important part of the polymorphism portion of object

inline函数

一个人想着一个人 提交于 2019-11-28 18:44:18
Inline函数特征: 相当于把内联函数里面的内容写在调用内联函数处; 相当于不用执行进入函数的步骤,直接执行函数体; 相当于宏,却比宏多了类型检查,真正具有函数特性; 编译器一般不内联包含循环、递归、switch 等复杂操作的内联函数; 在类声明中定义的函数,除了虚函数的其他函数都会自动隐式地当成内联函数。 优缺点    优点 内联函数同宏函数一样将在被调用处进行代码展开,省去了参数压栈、栈帧开辟与回收,结果返回等,从而提高程序运行速度。 内联函数相比宏函数来说,在代码展开时,会做安全检查或自动类型转换(同普通函数),而宏定义则不会。 在类中声明同时定义的成员函数,自动转化为内联函数,因此内联函数可以访问类的成员变量,宏定义则不能。 内联函数在运行时可调试,而宏定义不可以。    缺点 代码膨胀。内联是以代码膨胀(复制)为代价,消除函数调用带来的开销。如果执行函数体内代码的时间,相比于函数调用的开销较大,那么效率的收获会很少。另一方面,每一处内联函数的调用都要复制代码,将使程序的总代码量增大,消耗更多的内存空间。 inline 函数无法随着函数库升级而升级。inline函数的改变需要重新编译,不像 non-inline 可以直接链接。 是否内联,程序员不可控。内联函数只是对编译器的建议,是否对函数内联,决定权在于编译器 虚函数(virtual)可以是内联函数(inline)吗?

What does 'has virtual method … but non-virtual destructor' warning mean during C++ compilation?

喜欢而已 提交于 2019-11-28 17:48:00
#include <iostream> using namespace std; class CPolygon { protected: int width, height; public: virtual int area () { return (0); } }; class CRectangle: public CPolygon { public: int area () { return (width * height); } }; Has compilation warning Class '[C@1a9e0f7' has virtual method 'area' but non-virtual destructor How to understand this warning and how to improve the code? [EDIT] is this version correct now? (Trying to give answer to elucidate myself with the concept) #include <iostream> using namespace std; class CPolygon { protected: int width, height; public: virtual ~CPolygon(){};

Are pure virtual methods allowed within a template class?

心已入冬 提交于 2019-11-28 17:22:12
问题 Once before, I was certain that you couldn't do this, but the other day I was playing around with some code and it seemed to compile and work. I just want to verify that I am not just getting lucky. Can a template class have a pure virtual function - which I guess would also mean just plain virtual methods would be valid as well for the destructor? template <typename WordType> class DataSource { public: DataSource(); DataSource(DataSource const& other); virtual ~DataSource(); virtual void Put

C++ member function virtual override and overload at the same time

两盒软妹~` 提交于 2019-11-28 17:14:39
If I have a code like this: struct A { virtual void f(int) {} virtual void f(void*) {} }; struct B : public A { void f(int) {} }; struct C : public B { void f(void*) {} }; int main() { C c; c.f(1); return 0; } I get an error that says that I am trying to do an invalid conversion from int to void*. Why can't compiler figure out that he has to call B::f, since both functions are declared as virtual? After reading jalf's answer I went and reduced it even further. This one does not work as well. Not very intuitive. struct A { virtual void f(int) {} }; struct B : public A { void f(void*) {} }; int

virtual function call from base class

自作多情 提交于 2019-11-28 16:39:01
Say we have: Class Base { virtual void f(){g();}; virtual void g(){//Do some Base related code;} }; Class Derived : public Base { virtual void f(){Base::f();}; virtual void g(){//Do some Derived related code}; }; int main() { Base *pBase = new Derived; pBase->f(); return 0; } Which g() will be called from Base::f() ? Base::g() or Derived::g() ? Thanks... Johannes Schaub - litb The g of the derived class will be called. If you want to call the function in the base, call Base::g(); instead. If you want to call the derived, but still want to have the base version be called, arrange that the

How to design a C++ API for binary compatible extensibility

最后都变了- 提交于 2019-11-28 16:13:09
I am designing an API for a C++ library which will be distributed in a dll / shared object. The library contains polymorhic classes with virtual functions. I am concerned that if I expose these virtual functions on the DLL API, I cut myself from the possibility of extending the same classes with more virtual functions without breaking binary compatibility with applications built for the previous version of the library. One option would be to use the PImpl idiom to hide all the classes having virtual functions, but that also seem to have it's limitations: this way applications lose the

Virtual method called from derived instead of base

偶尔善良 提交于 2019-11-28 13:54:14
Can someone explain to me why is the overridden method being called when I cast the class into the base one: class Base { public virtual void VirtualMethod() { Console.WriteLine("Base virtual method"); } } sealed class Derived : Base { public override void VirtualMethod() { Console.WriteLine("Overriden method"); } } static void Main(String[] args) { Derived d = new Derived(); ((Base)d).VirtualMethod(); } I mean this code prints: Overriden method and not Base virtual method Its a run-time or compile-time future? I know i can call the Base's virtual method from the derived by calling base