I wrote my codes in my program, but i got this error every time when i compile my program<<
1 2 3
Error 1 error LNK2005: "public: void __thiscall MyFloat::Write(void)" (?Write@MyFloat@@QAEXXZ) already defined in MyFloat.obj C:
Error 2 error LNK1169: one or more multiply defined symbols found C:
#include <iostream>
usingnamespace std;
/*
Action: This assignment cells for doing a partial implementation of the abstract
data type "MyFloat". This ADT is to serve a specialized need for small floats
between 0 and 1 that can have up to 20 digits of accuracy. The creation of
the MyFloat class will allow calculations with with accuracy not possible with floats.
*/
class MyFloat{
private:
enum { MAX_DIGITS = 20 };
char Number[MAX_DIGITS + 1];
char NumberOfDigits;
public:
MyFloat()
{
NumberOfDigits = 0;
}
void Write();
//int read();
friendvoid AssignValue(MyFloat& X);
};
void MyFloat::Write(){
cout << "0.";
if (NumberOfDigits != 0)
for (int i = 1; i <= NumberOfDigits; i++)
{
cout << int(Number[i]);
}
else
cout << "?";
}
i want to link my program or codes to this program
#include <iostream>
#include "MyFloat.cpp"
usingnamespace std;
void AssignValue(MyFloat& X)
{
X.Number[1] = 1;
X.Number[2] = 2;
X.Number[3] = 3; // run program first this way with
X.NumberOfDigits = 0; // these numbers then change
} // X.NumberofDigits = 0, to test
// "0.?", which stands for an error
void main()
{
MyFloat X;
AssignValue(X);
cout << "X = ";
X.Write();
cout << endl << "Press Enter key to continue";
cin.ignore();
}
everything is good so far and my codes has no error, but i think only problem i got is linking between those programs.
Finally, i solved my problem. i just change header and compiler from setting, my project make it as header and another or second one make is as compiler. finally, works fine.