Is the virtual method "remote" in C ++ 0x?

The error message is apparently unlikely for the scenario when we try to use the delete a virtual method.

 prog.cpp:4:16: error: deleted function 'virtual void Test::foo()' prog.cpp:8:2: error: used here 

code

 struct Test : public Base { Test() {} virtual void foo () = delete; // error }; 

The virtual not delete method is possible for the same reason why they cannot remain unrealized in C ++ 03? Can I mention that Test intentionally does not implement virtual foo() ?

+4
source share
5 answers

The term use has a specific definition in the standard, and, in particular, for virtual functions, the definition is odr-used:

§3.2 / 2 (C ++ 0x FDIS) [...] The virtual member function is used by odr if it is not clean. [...]

Where odr is used is a new term in the upcoming standard that refers to using the previous standard:

§3.2 / 2 (current standard) [...] A virtual member function is used if it is not pure. [...]

My opinion is that the error message uses the term used to mean odr used in this particular case, and yes, the reason this violation is the same reason you cannot leave an unclean virtual function- member is not implemented.

+9
source

All unclean virtual functions must be implemented, whether you use them or not :

 struct Test { Test() {} virtual void foo(); }; int main() { Test* t = new Test; // ^ it seems to have to be dynamic allocation to coerce the error out } /* Output: /home/Y3oGMf/ccOLuYWf.o: In function `main': prog.cpp:(.text+0x17): undefined reference to `vtable for Test' collect2: ld returned 1 exit status */ 

I think you see a small odd message about using a remote function for the same reason. It is simply because of how everything works domestically. A more reasonable error message might be in the line where you tried to execute the delete a virtual element, saying: "This will not work, it will cause problems because this implementation must exist."

In any case, the delete function does not make sense. Inheritance adds functionality; it doesn’t take it off. Note how the creation of a member function of a virtual virtual function prohibits the creation of an entire class: derived classes must reimplement the functionality so that it is not lost.

+3
source

My understanding is the delete keyword to remove the default implementation that is generated by the compiler. For virtual methods, there is no default implementation generated by the compiler.

+2
source

Remote virtual functions are allowed, but cannot be overridden.

§10.3 (11) says:

A virtual function declared in a class must be defined as , or declared pure (10.4) in this class, or both; but no diagnosis is required (3.2).

§8.4.1 says that a remote function is defined .

And §10.3 (16) says:

A function with a remote definition (8.4) must not override a function that does not have a remote definition. Similarly, a function that does not have a remote definition must not override a function with a remote definition.

The purpose of this last rule is to provide diagnostics for calling a remote function at compile time.

Thus, the following code is poorly formed:

 struct Base { virtual void foo(); }; struct Derived : public Base { virtual void foo() = delete; }; 

But the following code is correctly generated:

 struct Base { virtual void foo() = delete; }; struct Derived : public Base { virtual void foo() = delete; }; 

Demo

The OP had either a compiler error or a QoI problem (it’s hard to say because it did not publish all the code), which has since been fixed.

+2
source

Perhaps you should not infer from a class that NEEDED something if your derived class cannot implement it. You probably don't need to infer from this class in the first place.

I like to say, "I'm building a better car. What kind of car, but does not drive the wheels." Are you sure this is a car, and first of all?

Or are you asking about it just out of curiosity?

0
source

All Articles