Declaration problem help pls

Hey everyone

I have a little problem.

I have installed lubuntu today on my old laptop.Then I created
new project in code::blocks and it had no compiler which was weird so
I installed g++ using terminal(sudo apt-get install g++)
everything went well then I downloaded SDL(libSDL2.dev) because I wanted to start developing
a simple game so tested it if it works by creating simple window and rederer in a main function.Everything was still good.So I then moved all that code into different class and then run it through pointer(game->init()) but when I tried to compile it boom like 1000 lines of errors basically saying that nothing was declared so I tried to look for the problem but nothing seemed wrong the header was included no compile error in the header.Then I tried to compile it using terminal still the same problem . so I tried to write simple program that just uses variable from header file and prints it on screen still the same problem.
Last edited on
Please show the code of "simple program".
// it says error: a was not declared in this scope;

#include "Header,h"

int main(int argc, char* argv[])
{
Header *hdr;
return 0;
}

//Header.h file
#ifndef HEADER_H
#define HEADER_H
#include <iostream>

class Header
{
public:
Header();
int a;

};
#endif

//Header.cpp file

#include "Header.h"

Header::Header
{
a = 100;
std::cout<< a << std::endl;
}
Last edited on
Please use code tags when posting code. See http://www.cplusplus.com/articles/jEywvCM9/

Which line of code does give the error?

I actually get a different message:
error: 'Header::Header' names the constructor, not the type


This:
1
2
3
Header::Header     // error
{
}

should be:
1
2
3
Header::Header()
{
}



Unrelated notes:
* Your main includes "Header,h". The comma is a typo?
* Your main merely declares a pointer. A forward declaration -- class Header; -- would suffice. Include is not needed.
* Your Header.h includes <iostream>, but does not need it. The .cpp does. Avoid unnecessary includes on header files.
* Is the flush necessary? The endl is '\n' + flush(). Usually the '\n' is enough.
Topic archived. No new replies allowed.