-2

This is the header file (no error here):

#ifndef BIOM_H
#define BIOM_H
#include <string>
class Biom {
public:
    Biom();
    ~Biom();
    std::string name;
};
#endif

And this is the C++ file (error in line 4):

#include "stdafx.h"
#include "Biom.h"

public:
Biom::Biom() {}
Biom::~Biom() {}
std::string Biom::name;
Timon Paßlick
  • 193
  • 1
  • 11
  • 1
    public/private/protected can only be used (and only means something) when doing declarations. Also, You don't need to define your 'name' variable in the CPP file. It is not static. – AlexG May 12 '17 at 19:44
  • You only need `std::string Biom::name;` outside of the class when that member is `static` – crashmstr May 12 '17 at 19:44
  • 4
    Get rid of `public:` from the cpp file. You only use it declarations, not definitions. Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list) – NathanOliver May 12 '17 at 19:44
  • http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list – Weak to Enuma Elish May 12 '17 at 19:45
  • @AlexG, nope, they can only be used in _declarations_, and one can put them in `.cpp` files as well. – ForceBru May 12 '17 at 19:45
  • @ForceBru updated. I didn't think of structs declared in cpp files. – AlexG May 12 '17 at 19:46

1 Answers1

0

This is the correct C++ file:

#include "stdafx.h"
#include "Biom.h"

Biom::Biom() {}
Biom::~Biom() {}

I could have omitted the constructor and destructor and let it be default generated. Then I wouldn't need the .cpp file at all.

Timon Paßlick
  • 193
  • 1
  • 11