c++ - NVCC & Cygwin Enables non-standard inheritance of struct within a class || How to return a subclass from a super class -


utilizing cygwin, vs15 compiler, , nvcc following compiles...

template typename<b>  class base {  int = 1;      template typename <d>    struct derived : public base<d> {        int derived_a = 2;         virtual int geta() override { return derived_a;}    }     virtual int geta() { return a;} }  int main() { base b<int> base;   std::cout << b.geta() << " " << b.getderived().geta() << std::endl; } 

//output 1 2 

however without usage of templates code not compile giving expected "invalid use of incomplete type base"

i wondering... given solve "superclass needs return subclass" pros/cons adding feature c++ standard.


likewise sake of science, if can post other compilers allow please do.

*edit -- tested vs15 compiler well


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -