前提・実現したいこと
ヘッダとソースファイルを分けてクラステンプレートで演算子のオーバーロードをしたいです
###ここに質問の内容を詳しく書いてください。
ヘッダでメンバ関数のプロトタイプ宣言、ソースファイルで記述したところエラーが出ます
検索して修正したりしたのですが別のエラーが出るだけでした
発生している問題・エラーメッセージ
エラーメッセージ color.cc:5:16: error: ‘T’ was not declared in this scope Color<V> Color<T>::operator= (const Color<U>&) { ^ color.cc:5:17: error: template argument 1 is invalid Color<V> Color<T>::operator= (const Color<U>&) { ^ color.cc:5:46: error: ‘Color<U> operator=(const Color<V>&)’ must be a nonstatic member function Color<V> Color<T>::operator= (const Color<U>&) {
該当のソースコード
C++ ####ヘッダファイル側 template<class T> class Color { (略) template<typename U, typename V> Color<V> operator= (const Color<U>&) &; ####ソースファイル側 template<typename U, typename V> Color<V> Color<T>::operator= (const Color<U>&) { } ソースコード
試したこと
ソースファイル側のテンプレートにTの追加したが別のエラー
color.cc:5:10: error: prototype for ‘Color<V> Color<T>::operator=(const Color<U>&)’ does not match any in class ‘Color<T>’ Color<V> Color<T>::operator= (const Color<U>&) { ^~~~~~~~ In file included from color.cc:1:0: rt05.h:34:11: error: candidates are: template<class T> template<class U> Color<T> Color<T>::operator=(const Color<T>&) & Color<T> operator= (const Color<T>&) &; ^~~~~~~~ rt05.h:31:11: error: template<class T> template<class U, class V> Color<V> Color<T>::operator=(const Color<U>&) & Color<V> operator= (const Color<U>&) &; ^~~~~~~~
補足情報(FW/ツールのバージョンなど)
g++ -v Using built-in specs. COLLECT_GCC=g++ COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/7/lto-wrapper OFFLOAD_TARGET_NAMES=nvptx-none OFFLOAD_TARGET_DEFAULT=1 Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion='Ubuntu 7.3.0-27ubuntu1~18.04' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu Thread model: posix gcc version 7.3.0 (Ubuntu 7.3.0-27ubuntu1~18.04)
make -v GNU Make 4.1 このプログラムは x86_64-pc-linux-gnu 用にビルドされました Copyright (C) 1988-2014 Free Software Foundation, Inc. ライセンス GPLv3+: GNU GPL バージョン 3 以降 <http://gnu.org/licenses/gpl.html> これはフリーソフトウェアです: 自由に変更および配布できます. 法律の許す限り、 無保証 です.
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/04 05:58