0

I'm facing a really stupid and infuriating problem, I was following a video on how to make a roguelike, I decided to stop after knowing how to print a level to the screen and actually start coding, then I got multiple errors on seamingly perfect code, I blammed the constructors so I decided to make a new project on visual studio to test the most stupid case, one main fuction, one clase with one constructor that does nothing, and I leaved all the work of making the class and the constructor to visual studio, I still got the goddammned issue, here's the error on that simplified version of the code, I would show the rogue like code but I would have to translate to english al the errors myself, and most of them have nothing to do with the actual error, because mostly they're complaining about missing ; in places where either there shouldn't be a ; or there alredy is one.

here's the code
    main.cpp:
    #include "stdafx.h"

    int main()
    {
    return 0;
    }
    test.h
    #include "stdafx.h"

    class test
    {
    public:
    test();
    };
    test.cpp
    #include "test.h"
    #include "stdafx.h"

    test::test(){
    }

yet with that simple auto-generated code, visual studio still complaints and gives me this error messages

c4430 missing type specifier - int assumed. Note: C++ does not support default-int

c2653 'test' : is not a class or namespace name

'test' : function should return a value; 'void' return type assumed

what should I do?

  • 2
    ` #include "test.h" #include "stdafx.h"` Reverse the order? – Ed Heal Nov 25 '17 at 05:59
  • The compiler assumes that everything up to and including `#include "stdafx.h"` is already precompiled, and so will not compile it again. You will have to consider that when ordering the `#include`s. – Bo Persson Nov 25 '17 at 12:42

1 Answers1

0

You have to define return type explicitly and return a value of that type if your function returns not void. Otherwise you will get that error.

class A
{
    int int_func();
    void void_func();
};

int A::int_func()
{
    return 0;
}
void A::void_func()
{
    // No return;
}
Pavlo Holotiuk
  • 230
  • 2
  • 10