How? Here is how it?
Good day to all of you!
I'm sorry, but I'm ashamed, but I can't figure out where the mistake is.
The saddest thing is that I Google more than an hour trying to study the code carefully, and I haven't found a catch.
I don't get it.
I'm not going to handle the underwater stones in the code.
D:\Classes\Com1vc\Com.cpp|20|error: request for member 'KeyVal' in '((ComplexType*)this)->ComplexType::real', which is of non-class type 'double'|
What is this? I didn't expect that. (ComplexType *)-ComplexType: Real is it from where?
What should I add to my code to fix it well? Where was I wrong?
Friendly and respectful waiting for a response, please!
Code:
#include<iostream>
using std::cout;
using std::endl;
template <class t>
//neq (t t1,t t2);
int neq (t,t); /*Ÿ€о‚о‚ип ˆаблонƒ „ƒнк†–—.*/
class ComplexType
{
public:
double real;
double imag;
private:
ComplexType(double r=0.0, double i=0.0) { real=r; imag=i;}
/*žпе€а†–йна „ƒнк†–я! =. ‘ез не— неможлива побƒдова ˆаблонно— „ƒнк†–— neq () для комплексни… ‡исел.*/
int operator != (ComplexType & KeyVal)
{
if (real==real.KeyVal&&imag==imag.KeyVal) return 0;
else return 1;
}
};
int main ()
{
// ’изна‡ен– ‚а п€о–н–†–ал–зован– зм–нн– ‚€Œо… ‚ип–в.
int i = 1, j = 2;
float k = 1.0, l = 2.0;
ComplexType CTw1(1.0,1.0), CTw2(2.0,2.0);
//На основ– ви€аз–в викликƒ ‚€ансля‚о€ бƒдƒ” ‚€и ˆаблонни… „ƒнк†–—.
cout << "neq() for int:" << neq(i,j) << endl;
cout << "neq() for float:" << neq(k,l) << endl;
cout << "neq() for ComplexType:" << neq(CTw2,CTw3) << endl;
return 0;
}
/*’изна‡ення ˆаблонƒ „ƒнк†–—.*/
template <class t>
int neq (t t1,t t2);
{
return t1 != t2 ? 1 : 0;
// return t1 != t2; /* На сп€авд– можно й ‚ак… */
}