code_farmer code_farmer - 1 year ago 94
C++ Question

what is this base: means? is it a standard c++ key word

The code as follows:

#include <iostream>

struct A {
virtual void foo() { std::cout << "hello world!" << std::endl; }

struct B : public A {
void foo() override { base:foo(); }

void main() {
A* p = new B();

delete p;

what is the 'base:' means? is it a standard key word in c++?

platform: win10 + vs2015 update3;

project type: win32 console project;

Answer Source

A somewhat known idiom would involve something like

struct B : public A {
    typedef A base;
    void foo() override { base::foo(); }

What you have there looks superficially similar, but it is not that. In your case base: is just a label, which affects nothing. Unless the code you presented is an intentional puzzle/joke, it might actually be an attempt to reproduce what I posted above by a person who just doesn't rememebr all the details.

In any case, base is not a keyword in C++ (and is not a keyword in VS2015 either).

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download