0

Problem

I want to assign values in a class definition which is in a separate header file from the class declaration cpp.

On compilation I recieve theses error messages:

error: ‘const std::map<unsigned int, std::basic_string<char> > bob::mRegexes’ is not a static member of ‘class bob’const std::map<uint,std::string> bob::mRegexes = {
                                   ^
error: ‘const std::map<unsigned int, std::basic_string<char> > bob::mResponses’ is not a  static member of ‘class bob’ const std::map<uint,std::string> bob::mResponses  = {

both of which have been absolutely infurriating because I do not understand why the compiler is ignoring thetypedef for std::string I feel like I'm missing something here but I'm not sure why the bob.h file is seeing the parameters differently than the bob.cpp.

bob.h

#ifndef BOB_H
#define BOB_H
#include <iostream>
#include <string>
#include <boost/regex.hpp>
#include <map>


typedef unsigned int uint;

// This was first to go when I started having problems.
/*using std::string;*/                                                                                                                                                                         
using std::map;
// boost::regex > c++11::regex (gcc doesn't follow standards).
using boost::regex;

class bob
{
  enum respond_to{
    QUESTION,
    YELL,
    NAME,
    DEFAULT,
    LENGTH
  };

public:
  static const respond_to mResponseTypes;
  static const map<uint,std::string> mRegexes;
  static const map<uint,std::string> mResponses;

  static std::string hey(std::string sentence);
  static const std::string* evaluate (const std::string& sentence);
  static const std::string* getResponse(const std::string& sentence, const respond_to& type) noexcept(true);
};
#endif

bob.cpp

#include "bob.h"

const std::map<uint,std::string> bob::mRegexes = {
  {QUESTION, "[a-z]+\\?"},
  {YELL,"[A-Z]+"}
};

const std::map<uint,std::string> bob::mResponses  = {
  {QUESTION,"Sure"},
  {YELL,"Whoah, chill out!"},
  {DEFAULT,"Whatever."}
};

  // ...  
  • Compiles fine here on VC 2013. What compiler are you using? Any chance it's an old GCC? – Christian Hackl Sep 26 '14 at 17:54
  • Fine on g++ 4.8.2 using `--std=c++0x`. – Thomas Sep 26 '14 at 17:55
  • By the way, the code has a couple of problems: Using `using` at global scope (so everyone who includes the header is forced to have the `using`s), `ALL_UPPERCASE` for non-macros, returning `const std::string *` rather than `const std::string &` or simply `std::string`. – Christian Hackl Sep 26 '14 at 17:56
  • Thanks @ChristianHackl returning a pointer was part of a work around with a different problem but I'm beginning to think that it is a compiler problem. – Max Mansfield Sep 26 '14 at 18:38
  • @Thomas I'm running gcc 4.9.1 and using a cmake file that is genrated from a provided `CMakeList` (I'm not sure if you're familiar with exercism.io) in it they recommend using --std=c++11 functons and they say that it is implemented in the cmake although they tell you that it is not neccessary to edit it so i haven't. I'm guessing that is the root of my problems. – Max Mansfield Sep 26 '14 at 18:42
  • @ChristianHackl I see what you mean about the global `using` and the confusing names :| yikes! – Max Mansfield Sep 26 '14 at 18:45

0 Answers0