Just trying to write a basic c++ program for my college project
I declared a sample class called TestClass
and put it in the testclass.h
file in header files
folder.
class TestClass
{
private:
int an;
public:
TestClass(void);
int a[];
void print();
void compute();
void get();
~TestClass(void);
};
And then to implement
the above class, I created a new file in Source Files
folders and then wrote this piece of code.
#include <iostream>
#include <conio.h>
#include "TestClass.h"
TestClass:: vinayak(void)
{
}
void TestClass:: print()
{
}
void TestClass:: compute()
{
}
void TestClass:: get()
{
}
TestClass:: ~TestClass(void)
{
}
I then created a new file called Source.cpp
and then wrote the piece of code.
#include "TestClass.h"
#include "TestClass.cpp"
void main()
{
TestClass TObject = TestClass();
TObject.get();
}
Here I am getting an error like below:
public: void __thiscall TestClass::compute(void)" already defined in Source.obj
Any ideas why ?
EDIT:
Based on @Marco's comment, I was able to compile the program.
Also, I had to remove the constructor
and the destructor
declarations in the header file
.
This made the program to work fine :)