Apress / design-patterns-in-modern-cpp

Source code for 'Design Patterns in Modern C++' by Dmitri Nesteruk
http://www.apress.com/9781484236024
Other
536 stars 192 forks source link

composite - neurons #2

Open klukaspl opened 6 years ago

klukaspl commented 6 years ago

I have a problem with compilation under gcc:

invalid use of incomplete type struct 'Neuron'.

In template struct SomeNeurons the compiler points from and to as problematic.

nesteruk commented 3 years ago

What compiler are you using? On MSVC the example builds just fine.

edgarpettijohn commented 2 years ago

I'm having the same issue using both clang++ and g++ $ clang++ -v FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe) Target: x86_64-unknown-freebsd13.0 Thread model: posix InstalledDir: /usr/bin

$ g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc10/gcc/x86_64-portbld-freebsd13.0/10.3.0/lto-wrapper Target: x86_64-portbld-freebsd13.0 Configured with: /wrkdirs/usr/ports/lang/gcc10/work/gcc-10.3.0/configure --enable-multilib --with-build-config=bootstrap-debug --disable-nls --enable-gnu-indirect-function --enable-plugin --libdir=/usr/local/lib/gcc10 --libexecdir=/usr/local/libexec/gcc10 --program-suffix=10 --with-as=/usr/local/bin/as --with-gmp=/usr/local --with-gxx-include-dir=/usr/local/lib/gcc10/include/c++/ --with-ld=/usr/local/bin/ld --with-pkgversion='FreeBSD Ports Collection' --with-system-zlib --without-zstd --enable-languages=c,c++,objc,fortran --prefix=/usr/local --localstatedir=/var --mandir=/usr/local/man --infodir=/usr/local/share/info/gcc10 --build=x86_64-portbld-freebsd13.0 Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.3.0 (FreeBSD Ports Collection)

$ g++ -I/usr/local/include -std=c++20 -o neuron neurons.cpp neurons.cpp: In member function 'void SomeNeurons::connect_to(T&)': neurons.cpp:21:9: warning: invalid use of incomplete type 'struct Neuron' 21 | from.out.push_back(&to); | ^~~~ neurons.cpp:10:8: note: forward declaration of 'struct Neuro' 10 | struct Neuron; | ^~ neurons.cpp:22:9: warning: invalid use of incomplete type 'struct Neuron' 22 | to.in.push_back(&from); | ^~ neurons.cpp:10:8: note: forward declaration of 'struct Neuro' 10 | struct Neuron; | ^~

The error with clang++ is pretty much the same. Disregard above where Neuron was truncated to Neuro. My terminal cut it off for some reason.