2 Replies - 3299 Views - Last Post: 09 December 2012 - 09:27 PM Rate Topic: -----

#1 BreaksOnDust  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-December 12

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

Posted 09 December 2012 - 07:21 PM

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:

Is This A Good Question/Topic? 0
  • +

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

#2 jimblumberg  Icon User is online

  • member icon


Reputation: 4141
  • View blog
  • Posts: 12,892
  • Joined: 25-December 09

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

Posted 09 December 2012 - 07:51 PM

Quote

I want the name for the class to be diffclass while the name for the constructor in diffclass to be diffstruct.


The constructor must have the same name as the class.

Jim
Was This Post Helpful? 2
  • +
  • -

#3 BreaksOnDust  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 38
  • Joined: 09-December 12

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

Posted 09 December 2012 - 09:27 PM

I see... Tired me had forgotten that. Thanks mate!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1