That's name of the error message I get when I try and compile this program.
I've just started learning c++ again and I'm making a simple program with a separate header called "diffclass.h.
I want to have a different name for the function/constructor that gets mentioned in the diffclass.h-file. But it won't compile unless all names are exactly the same.
I want the name for the class to be diffclass while the name for the constructor in diffclass to be diffstruct.
Error message:
main.cpp
diffclass.h
diffclass.cpp
Thank you for your help!
I've just started learning c++ again and I'm making a simple program with a separate header called "diffclass.h.
I want to have a different name for the function/constructor that gets mentioned in the diffclass.h-file. But it won't compile unless all names are exactly the same.
I want the name for the class to be diffclass while the name for the constructor in diffclass to be diffstruct.
Error message:
||=== DifferentFiles, Debug ===| C:\Users\User\Desktop\DifferentFiles\diffclass.h|8|error: ISO C++ forbids declaration of 'diffstruct' with no type [-fpermissive]| C:\Users\User\Desktop\DifferentFiles\diffclass.cpp|4|error: ISO C++ forbids declaration of 'diffstruct' with no type [-fpermissive]| C:\Users\User\Desktop\DifferentFiles\diffclass.cpp||In member function 'int diffclass::diffstruct()':| C:\Users\User\Desktop\DifferentFiles\diffclass.cpp|7|warning: no return statement in function returning non-void [-Wreturn-type]| ||=== Build finished: 2 errors, 1 warnings (0 minutes, 0 seconds) ===|
main.cpp
#include <iostream>
#include "diffclass.h"
using namespace std;
int main()
{
diffclass myObject;
return 0;
}
diffclass.h
#ifndef DIFFCLASS_H
#define DIFFCLASS_H
class diffclass
{
public:
diffstruct(); //function/constructor?
};
#endif // DIFFCLASS_H
diffclass.cpp
#include <iostream>
#include "diffclass.h"
using namespace std;
diffclass::diffstruct() //CLASS::CONSTRUCTOR
{
cout << "I am a banana" << endl;
}
Thank you for your help!