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

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -