Я пытаюсь выучить C ++, поэтому я написал в Windows программу с бесконечным циклом, которая просит пользователей вводить два целых числа и считывает значения синуса и тангенса этих чисел, а также, является ли первое целое число кратнымсекунды.
Program1Math.h
#ifndef PROGRAM1MATH_H_
#define PROGRAM1MATH_H_
class Program1Math {
public:
Program1Math(int, int);
void calculateSine(int);
void calculateTangent(int);
void calculateModulus();
};
#endif
Program1Math.cpp
#include "Program1Math.h"
#include < iostream >
#include < math.h >
using namespace std;
int c;
int d;
Program1Math::Program1Math(int a, int b)
{
c=a;
d=b;
}
void Program1Math::calculateSine(int a)
{
cout<<"\nSine("<< a <<")\t=\t"<< sin(a);
}
void Program1Math::calculateTangent(int a)
{
cout<<"\nTan("<< a <<")\t=\t"<< tan(a);
}
void Program1Math::calculateModulus()
{
if (c%d==0)
{
cout<<"\n"<< c <<" is a multiple of "<< d <<"!";
}
else
{
cout<<"\n"<< c <<" is not a multiple of "<< d <<".";
}
}
Program1.cpp
#include < iostream >
#include "Program1Math.h"
using namespace std;
int main()
{
int num1;
int num2;
int i=1;
while (i>0){
cout<<"Please enter the first integer number:\n";
cin>>num1;
cout<<"Please enter the second integer number:\n";
cin>>num2;
Program1Math p(num1, num2);
p.calculateModulus();
p.calculateSine(num1);
p.calculateTangent(num1);
p.calculateSine(num2);
p.calculateTangent(num2);
cout<<"\n\n";
}
return 0;
}
Программа соберети корректно работать (кроме проблемы форматирования для функции convertTangent) в Eclipse.Однако я не могу заставить программу работать в среде Unix.Программа будет собираться, но когда я пытаюсь ее запустить, я получаю следующее сообщение об ошибке:
Program1Math: In function `_start':
(.text+0x0): multiple definition of `_start'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.text+0x0): first defined here
Program1Math: In function `_fini':
(.fini+0x0): multiple definition of `_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crti.o:(.fini+0x0): first defined here
Program1Math:(.rodata+0x0): multiple definition of `_IO_stdin_used'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.rodata.cst4+0x0): first defined here
Program1Math: In function `__data_start':
(.data+0x0): multiple definition of `__data_start'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crt1.o:(.data+0x0): first defined here
Program1Math:(.rodata+0x8): multiple definition of `__dso_handle'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtbegin.o:(.rodata+0x0): first defined here
Program1Math: In function `_init':
(.init+0x0): multiple definition of `_init'
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../lib64/crti.o:(.init+0x0): first defined here
/usr/lib/gcc/x86_64-redhat-linux/4.1.2/crtend.o:(.dtors+0x0): multiple definition of `__DTOR_END__'
Program1Math:(.dtors+0x8): first defined here
collect2: ld returned 1 exit status
Кто-нибудь знает, в чем может быть проблема?