나는 클래스가 (기술적으로) 아무 관계가 없기 때문에 그것을 의심하는거야,하지만 난 다른 템플릿 구현의 친구와 함께 클래스를 만들 수있는 방법은 무엇입니까?
는 X : 나는 교육적인 이유로 내 자신의 고정 소수점 클래스를 만들기로 장난 해요
. 유일한 이유 누구도 다른 고정 점에서 고정 된 지점을 만들 때 될 기본 고정 소수점 값을 얻을 필요가 whould 예를 들어
그래서 기본적으로template <typename I, size_t R>
class FixedPoint
{
public:
template <typename J, size_t Rj>
FixedPoint(const FixedPoint<J,Rj>& ref)
{
...
std::ptrdiff_t radix_diff = R-Rj;
val_ = ref.val_ >> radix_diff;//there is more to this but you get the idea
}
private:
I val_;
}
, 정말 다음과 같은 사실을하고 싶습니다 :
template <typename J,typename Rj>
friend FixedPoint<J,Rj>::FixedPoint(const FixedPoint<I,R>& ref);
분명히 불가능합니다. val_ public에 getter 함수를 만드는 것 이외의 다른 방법이 있습니까?
편집 :
/home/user/source/testdir/main.cpp: In instantiation of 'class FixedPoint<signed char, 4ul>':
/home/user/source/testdir/main.cpp:115:24: required from here
/home/user/source/testdir/main.cpp:64:10: internal compiler error: unexpected expression 'Rj' of kind template_parm_index
friend FixedPoint<J,Rj>::FixedPoint(const FixedPoint<I,R>& ref);
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://bugzilla.redhat.com/bugzilla> for instructions.
Preprocessed source stored into /tmp/ccWaztkQ.out file, please attach this to your bugreport.
make[2]: *** [CMakeFiles/TestProgram.dir/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/TestProgram.dir/all] Error 2
make: *** [all] Error 2
15:17:06: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project TestProgram (kit: Desktop)
When executing step 'Make'
http://stackoverflow.com/a/3292852/596167 –
입니다 어리석은 교육 프로젝트,하지만 난 내 우정 엄격한 습관입니다 : 나는 단지 생성자에게 그것을주고 싶습니다 : - P – IdeaHat
Btw 당신이 진정으로되고 싶은 코드는 '템플릿 '대신에이 방법을 사용할 수 없습니다. –