Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

IS0 C++ forbids declaration of 'diffstruct' with no Type [-fpe

$
0
0
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:
||=== 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! :bananaman:

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>