Difficulties with Pointers in C++ / Linking error - c++

When compiling my code I get the following error:
LNK2019 unresolved external symbol "public: class QuantLib::Matrix
const & __cdecl SachLib::AWDCalculator::RSB(void)const "
(?RSB#AWDCalculator#SachLib##QEBAAEBVMatrix#QuantLib##XZ) referenced
in function "protected: void __cdecl
SachLib::CalculationEngine_Sach::set_results(class
boost::shared_ptr &)const "
(?set_results#CalculationEngine_Sach#SachLib##IEBAXAEAV?$shared_ptr#VAWDCalculator#SachLib###boost###Z)
It is found in CalculationEngine_Sach.obj in line 1.
Here is my code:
Abwicklungsdreieck and Gewichtungsfaktoren basically consists out of a Matrix and are obtained by its respective Reader. I think the names of their methods are unambiguous.
main.cpp:
#include "AbwicklungsdreieckReader.h"
#include "Abwicklungsdreieck.h"
#include "GewichtungsfaktorenReader.h"
#include "Gewichtungsfaktoren.h"
#include "Tarif_Sach.h"
#include "CalculationEngine_Sach.h"
#include "CalculationEngine_Sach_Typ1.h"
#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
}
#endif
using namespace QuantLib;
using namespace SachLib;
int main()
{
std::cout << "\n\n\nTest Chain-Ladder-Verfahren\n\n";
std::string input1 = "C:/Users/D91476/Desktop/LifeLib_Sol/awd.csv";
std::string input2 = "C:/Users/D91476/Desktop/LifeLib_Sol/gwf.csv";
boost::shared_ptr<PricingEngine> EngineTyp1(new CalculationEngine_Sach_Typ1());
SachLib::AbwicklungsdreieckReader input1Reader(input1);
SachLib::GewichtungsfaktorenReader input2Reader(input2);
SachLib::Abwicklungsdreieck AWD = input1Reader.get_awd();
std::cout << "\nInput 1: Abwicklungsdreieck\n\n";
std::cout << AWD.get_Matrix() << "\n";
SachLib::Gewichtungsfaktoren GWF = input2Reader.get_gwf();
std::cout << "\nInput 2: Gewichtungsfaktoren\n\n";
std::cout << GWF.get_Matrix();
Tarif_Sach *tarifsach1;
tarifsach1 = new Tarif_Sach_Typ1(AWD, GWF);
tarifsach1->setPricingEngine(EngineTyp1);
EngineTyp1->calculate();
}
By testing I found out that the error appears because of the following line:
boost::shared_ptr<PricingEngine> EngineTyp1(new CalculationEngine_Sach_Typ1());
AWDCalculator.h
#pragma once
#include "Tarif_Sach.h"
#include "Abwicklungsdreieck.h"
#include "Gewichtungsfaktoren.h"
#ifndef _AWDCalculator_H
#define _AWDCalculator_H
namespace SachLib {
class AWDCalculator {
public:
AWDCalculator();
AWDCalculator(Tarif_Sach::arguments *arguments);
AWDCalculator(Abwicklungsdreieck awd, Gewichtungsfaktoren gwf);
AWDCalculator(const AWDCalculator &obj);
AWDCalculator& operator=(AWDCalculator const& rhs);
//! Fills vectors.
void update(Tarif_Sach::arguments *arguments);
// Logic
void calculate(Abwicklungsdreieck awd, Gewichtungsfaktoren gwf);
//! \name Getter
//#{
const Abwicklungsdreieck& awd() const;
const Gewichtungsfaktoren& gwf() const;
const Matrix& estimated_costs_matrix() const;
const Matrix& RSB_all() const;
const Matrix& RSB() const;
//#}
Tarif_Sach::arguments *arguments_;
protected:
AWDCalculator *results_;
Abwicklungsdreieck awd_;
Gewichtungsfaktoren gwf_;
//! \name Outputs
//#{
Matrix estimated_costs_matrix_;
Matrix RSB_all_;
Matrix RSB_;
//#}
};
}
#endif
AWDCalculator.cpp
#include "AWDCalculator.h"
SachLib::AWDCalculator::AWDCalculator()
{
}
SachLib::AWDCalculator::AWDCalculator(Tarif_Sach::arguments *arguments)
: AWDCalculator(arguments->awd, arguments->gwf)
{
arguments_ = arguments;
}
SachLib::AWDCalculator::AWDCalculator(Abwicklungsdreieck awd, Gewichtungsfaktoren gwf)
: awd_(awd),
gwf_(gwf)
{
results_ = new AWDCalculator(awd, gwf);
calculate(awd, gwf);
}
SachLib::AWDCalculator::AWDCalculator(const AWDCalculator& obj)
{
arguments_ = obj.arguments_;
awd_ = obj.awd_;
gwf_ = obj.gwf_;
}
SachLib::AWDCalculator& SachLib::AWDCalculator::operator=(AWDCalculator const& rhs)
{
arguments_ = rhs.arguments_;
awd_ = rhs.awd_;
gwf_ = rhs.gwf_;
return *this;
}
void SachLib::AWDCalculator::update(Tarif_Sach::arguments *arguments)
{
results_ = new AWDCalculator(arguments);
arguments_ = arguments;
awd_ = arguments->awd;
gwf_ = arguments->gwf;
}
void SachLib::AWDCalculator::calculate(Abwicklungsdreieck awd, Gewichtungsfaktoren gwf)
{
// RSB_, RSB_all_ and estimated_costs_matrix_ get calculated here with the input awd and gwf
}
inline const Matrix& SachLib::AWDCalculator::estimated_costs_matrix() const
{
return estimated_costs_matrix_;
}
inline const Matrix& SachLib::AWDCalculator::RSB_all() const
{
return RSB_all_;
}
inline const Matrix& SachLib::AWDCalculator::RSB() const
{
return RSB_;
}
inline const SachLib::Abwicklungsdreieck& SachLib::AWDCalculator::awd() const
{
return awd_;
}
inline const SachLib::Gewichtungsfaktoren& SachLib::AWDCalculator::gwf() const
{
return gwf_;
}
CalculationEngine_Sach.h
#pragma once
#ifndef SachLib_calculationengine_sach_hpp
#define SachLib_calculationengine_sach_hpp
#include "Tarif_Sach.h"
#include "AWDCalculator.h"
using namespace QuantLib;
namespace SachLib {
class CalculationEngine_Sach : public Tarif_Sach::engine {
public:
CalculationEngine_Sach();
void calculate() const;
protected:
mutable boost::shared_ptr<AWDCalculator> AWDCalculator_;
void set_results(boost::shared_ptr<AWDCalculator> &awdCalculator) const;
};
}
#endif
CalculationEngine_Sach.cpp
#include "CalculationEngine_Sach.h"
#include "Tarif_Sach.h"
#include "AWDCalculator.h"
using namespace QuantLib;
namespace SachLib {
CalculationEngine_Sach::CalculationEngine_Sach()
{
}
void CalculationEngine_Sach::calculate() const
{
arguments_.AWDCalculator->update(&arguments_);
CalculationEngine_Sach::set_results(arguments_.AWDCalculator);
}
void CalculationEngine_Sach::set_results(boost::shared_ptr<AWDCalculator> &awdCalculator) const
{
results_.estimated_costs_matrix = awdCalculator->estimated_costs_matrix();
results_.RSB_all = awdCalculator->RSB_all();
results_.RSB = awdCalculator->RSB();
// because of the above three lines the error appears
}
}
CalculationEngine_Sach_Typ1.h
#pragma once
#include "CalculationEngine_Sach.h"
namespace SachLib {
class CalculationEngine_Sach_Typ1 : public CalculationEngine_Sach
{
public:
CalculationEngine_Sach_Typ1();
};
}
CalculationEngine_Sach_Typ1.cpp
#include "CalculationEngine_Sach_Typ1.h"
SachLib::CalculationEngine_Sach_Typ1::CalculationEngine_Sach_Typ1()
{}
If anyone could help I'd be much grateful.

You marked that function inline in the .cpp:
inline const Matrix& SachLib::AWDCalculator::RSB() const
In this case the compiler does not have to generate an out-of-line definition, unless it is needed in that translation unit (e.g. function address is taken). And that causes the linker error.
Remove inline from the function definition to make the compiler generate an out-of-line definition to fix the linker error.

you'll need to find the include file that has the definition for "Matrix" - that's what the error is showing.

Related

expected class name before '{' token. C++ inheritance issue

I've been on this for ages and did a lot of research and couldn't find an answer.
I have 4 classes: BuildingBase, CustomBuildingBase, Attackable, Nexus.
CustomBuildingBase is inherited from BuildingBase and Attackable, Nexus is inherited from CustomBuildingBase
I get this error in my nexus.h file
expected class name before '{' token.
My code:
custombuildingbase.h
#ifndef CUSTOMBUILDINGBASE_H
#define CUSTOMBUILDINGBASE_H
#include "buildings/buildingbase.h"
#include "handlerandmanager/gameeventhandler.h"
#include "handlerandmanager/gamemanager.h"
#include "attackable.h"
namespace Whiskas {
class CustomBuildingBase : public Course::BuildingBase, public Attackable
{
public:
CustomBuildingBase() = delete;
explicit CustomBuildingBase(
const std::shared_ptr<gameEventHandler>& eventhandler,
const std::shared_ptr<gameManager>& objectmanager,
const std::shared_ptr<Course::PlayerBase>& owner,
const int& tilespaces = 1,
const Course::ResourceMap& buildcost = {},
const Course::ResourceMap& production = {},
int health=3,
int attack=0
);
};
}
#endif // BUILDINGBASE_H
nexus.h:
#ifndef NEXUS_H
#define NEXUS_H
#include "buildings/custombuildingbase.h"
#include "core/resourcemaps.h"
namespace Whiskas {
static const Course::ResourceMap OUTPOST_PRODUCTIONMAP = {
{Course::BasicResource::MONEY, -10}
};
class Nexus : public CustomBuildingBase
{ //<--------------this is where I get the error
public:
Nexus() = delete;
explicit Nexus(
const std::shared_ptr<gameEventHandler>& eventhandler,
const std::shared_ptr<gameManager>& objectmanager,
const std::shared_ptr<Course::PlayerBase>& owner,
const int& tilespaces = 1,
const Course::ResourceMap& buildcost = Course::ConstResourceMaps::OUTPOST_BUILD_COST,
const Course::ResourceMap& production = Course::ConstResourceMaps::OUTPOST_PRODUCTION,
int health = 3,
int attack = 0
);
virtual ~Nexus() = default;
virtual std::string getType() const override;
virtual void onBuildAction() override;
virtual Course::ResourceMap getProduction() override;
}; // class Nexus
} // namespace Whiskas
#endif // NEXUS_H

Variable or field declared void C++

I am making a school assignment, but I am getting a strange error. I have tried to google it, but nothing helped.
So I have a file called main.cpp. Within this file I have some includes and code.
This:
#include <iostream>
#include <stdexcept>
#include <string>
using namespace std;
#include "RentalAdministration.h"
#include "Limousine.h"
#include "Sedan.h"
void addTestDataToAdministration(RentalAdministration* administration)
{
string licencePlates[] = {"SD-001", "SD-002", "SD-003", "SD-004", "LM-001", "LM-002"};
for (int i = 0; i < 4; i++)
{
Car* sedan = new Sedan("BMW", "535d", 2012 + i, licencePlates[i], false);
administration->Add(sedan);
}
for (int i = 4; i < 6; i++)
{
Car* limousine = new Limousine("Rolls Roys", "Phantom Extended Wheelbase", 2015, licencePlates[i], true);
administration->Add(limousine);
}
}
int main( void )
{
RentalAdministration administration;
addTestDataToAdministration(&administration);
}
So the compiler tells me that the variable: "RentalAdministration administration" does not exist.
So if we have look in my rentaladministration header. We see this:
#ifndef RENTALADMINISTRATION_H
#define RENTALADMINISTRATION_H
#include <vector>
#include "car.h"
class RentalAdministration
{
private:
std::vector<Car*> Cars;
Car* FindCar(std::string licencePlate);
Car* FindCarWithException(std::string licencePlate);
public:
std::vector<Car*> GetCars() const {return Cars;}
bool Add(Car* car);
bool RentCar(std::string licencePlate);
double ReturnCar(std::string licencePlate, int kilometers);
void CleanCar(std::string licencePlate);
RentalAdministration();
~RentalAdministration();
};
#endif
This is the exact error:
src/main.cpp:18:34: error: variable or field ‘addTestDataToAdministration’ declared void
void addTestDataToAdministration(RentalAdministration* administration)
^
src/main.cpp:18:34: error: ‘RentalAdministration’ was not declared in this scope
src/main.cpp:18:56: error: ‘administration’ was not declared in this scope
void addTestDataToAdministration(RentalAdministration* administration)
Help will be appreciated!
Edit:
I am getting warnings in sublime for the Sedan and Limousine headers. Something that has to do with some static constants. I think it was called a GNU extension. Maybe it has something to do with it.
Even when I comment the call of that function out. I get the same error.
I am calling that function nowhere else.
Some people say that the cause might be in these headers:
#ifndef LIMOUSINE_H
#define LIMOUSINE_H
#include "Car.h"
//c
class Limousine : public Car
{
private:
bool needsCleaning;
bool hasMiniBar;
static const double priceperkm = 2.5;
public:
double Return(int kilometers);
void Clean();
bool GetHasMiniBar() const { return hasMiniBar;}
void SetHasMiniBar(bool value) {hasMiniBar = value;}
Limousine(std::string manufacturer, std::string model, int buildYear, std::string licencePlate, bool hasminiBar);
~Limousine();
};
#endif
2:
#ifndef SEDAN_H
#define SEDAN_H
#include "Car.h"
//c
class Sedan : public Car
{
private:
int lastCleanedAtKm;
bool hasTowBar;
bool needsCleaning;
static const double priceperKm = 0.29;
public:
void Clean();
int GetLastCleanedAtKm() const {return lastCleanedAtKm;}
void SetLastCleanedAtKm(bool value){ lastCleanedAtKm = value;}
bool GetHasTowBar() const {return hasTowBar;}
void SetHasTowBar(bool value) {hasTowBar = value;}
bool GetNeedsCleaning() const {return needsCleaning;}
void SetNeedsCleaning(bool value){needsCleaning = value;}
Sedan(std::string manufacturer, std::string model, int buildYear, std::string licencePlate, bool hastowBar);
~Sedan();
};
#endif
class Limousine : public Car
{
private:
static const double priceperkm = 2.5;
...
}
Remove the static and declare the member simply as const double, example:
class Limousine : public Car
{
private:
const double priceperkm = 2.5;
...
}
The error message ‘RentalAdministration’ was not declared in this scope indicates that the right header file for RentalAdministration was not included. Check the file names to make sure class declaration for RentalAdministration is in the right file.
Restarting the terminal has somehow solved this error. I got another error this time, which I solved already. I missed the destructor. It stood in the header file, but not in the cpp file.
Buggy terminals...

how can I use constructors in place of setter member functions

my program basically depends on setters to initialize the data in my object instances but I want to remove them and have constructors in place of the setters, Is there a way I can do this or can anybody provide me a reference?
Instantiate object
//Using SDL and standard IO
#include <SDL.h>
#include <stdio.h>
#include <iostream>
#include <string>
#include <iomanip>
#include <archer.hpp>
#include <ctime>
#include <ArmouredArcher.hpp>
#include <RNGI.hpp>
using namespace std; //Declaring use of namespace std
void instantiateMuskateer();
int main(int argc, char* argv[])
{
//init muskateer object
instantiateMuskateer();
system("pause");
return 0;
}
Instantiation, Activity and destruction
void instantiateMuskateer()
{
Archer* Muskateer = new Archer();
Muskateer->setName("Brett");
delete Muskateer;
}
.hpp file
#ifndef _Archer_
#define _Archer_
#include <string>
class Archer
{
public:
inline Archer() :
name(""),
healthpoints(0),
baseDamage(0),
range(0)
{ ; } //All Member varials are in a known state
inline Archer(std::string name, int healthpoints, int baseDamage, int range) :
name(name),
healthpoints(healthpoints),
baseDamage(baseDamage),
range(range) //All member variables are in a known state
{
;
}
inline ~Archer() { ; } // empty destructor
inline std::string getName() { return name; }
inline void setName(std::string name) { this->name = name; }
inline int getHealthPoints() { return healthpoints; }
inline void setHealthPoints(int healthpoints) { this->healthpoints = healthpoints; }
inline int getBaseDamage() { return baseDamage; }
inline void setBaseDamage(int baseDamage) { this->baseDamage = baseDamage; }
inline int getRange() { return range; }
inline void setRange(int range) { this->range = range; }
/*std::string getName(); //getter for name
void setName(std::string name); //Set the name
int getHealthPoints();
void setHealthPoints(int healthpoints);
int getBaseDamage();
void setBaseDamage(int baseDamage);
int getRange();
void setRange(int range); */
protected:
private:
// copy constructor
Archer(const Archer& other) = delete;
// overload assignment operator
Archer& operator=(const Archer& other) = delete;
std::string name;
int healthpoints;
int baseDamage;
int range;
};
#endif
In your example, it is really simple, you just have to take the parameters you need in your constructor:
Archer(std::string n) :
name(n),
healthpoints(0),
baseDamage(0),
range(0)
{} //All Member varials are in a known state
And then you can simply do that:
void instantiateMuskateer()
{
Archer* Muskateer = new Archer("Brett");
delete Muskateer;
}
A few comments not related, but to improve your code. Writing inline is useless when you declare and implement your functions inside your class, the inline is implied. Also, if your destructor does nothing, you should not define it or use = default, that way you can enable some optimizations from the compiler.
Also, in your previous function i see no need to allocate the object on the heap, it is again a loss of performance and a source of error (such as forgetting to delete the object), allocate it on the stack:
void instantiateMuskateer()
{
Archer Muskateer("Brett");
// do your things
}
Or use a unique_ptr.

One or more multiply defined symbols found, error LNK1169 C++

Sorry for the lack of a descriptive title.
I'm getting an error "one or more multiply defined symbols found"; to be more specific, I'm getting 46 of them. One for each function in my header/source files. Using Visual Studios 2013.
Here is the relevant source code:
augments.h
#ifndef AUGMENTS_H_
#define AUGMENTS_H_
namespace Augments {
// only used for pass-ins for constructors
enum class Weapon_Type {
sword
};
enum class Head_Type {
head
};
enum class Body_Type {
body
};
// the player (Monster) has a head, body and weapon
// that augments his abilities. This will mostly
// be the thing that draws to the screen for each
// augmentation, but more importantly it contains
// specific statistics about each one.
// So if there was a body that was able to fly,
// there would be a bool that denotes this ability.
class Head : public Actor {
const Head_Type type;
public:
Head(Head_Type);
void Update(float dt);
};
class Body : public Actor {
const Body_Type type;
public:
Body(Body_Type);
void Update(float dt);
};
class Weapon : public Actor {
const Weapon_Type type;
public:
Weapon(Weapon_Type);
void Update(float dt);
};
}
using AugHead = Augments::Head;
using AugBody = Augments::Body;
using AugWep = Augments::Weapon;
#endif
augments.cpp
#include "stdafx.h"
#include "Angel.h"
#include "Augments.h"
#include "LD33.h"
Augments::Head::Head(Augments::Head_Type x) : type(x) {
switch ( x ) {
case Head_Type::head:
SetSprite("Images\\head.png");
break;
};
};
void Augments::Head::Update(float dt) {
SetPosition(Game::thePlayer->GetPosition().X,
Game::thePlayer->GetPosition().Y-
MathUtil::ScreenToWorld(Vec2i(0,40)).Y);
};
Augments::Body::Body(Augments::Body_Type x) : type(x) {
switch ( x ) {
case Body_Type::body:
SetSprite("Images\\body.png");
break;
};
}
void Augments::Body::Update(float dt) {
SetPosition(Game::thePlayer->GetPosition().X,
Game::thePlayer->GetPosition().Y);
}
Augments::Weapon::Weapon(Augments::Weapon_Type x ) : type(x) {
switch ( x ) {
case Weapon_Type::sword:
SetSprite("Images\\weapon.png");
break;
}
}
void Augments::Weapon::Update(float dt) {
SetPosition(Game::thePlayer->GetPosition().X,
Game::thePlayer->GetPosition().Y-
MathUtil::ScreenToWorld(Vec2i(0,-40)).Y);
}
monster.h
// monster related
#include "Augments.h"
#include "Angel.h"
#ifndef MONSTER_H_
#define MONSTER_H_
namespace Player {
// contains information like health attack etc
// but more important body types
class Monster : public PhysicsActor {
int max_health, curr_health;
int attack_damage;
Augments::Head* frame_head;
Augments::Weapon* frame_weapon;
Augments::Body* frame_body;
public:
void Refresh(float dt);
int R_Max_Health() const;
int R_Curr_Health() const;
int R_Attack_Damage() const;
Augments::Head* R_Frame_Head();
Augments::Weapon* R_Frame_Weapon();
Augments::Body* R_Frame_Body();
void Set_Max_Health(int);
void Set_Curr_Health(int);
void Add_Curr_Health(int);
void Set_Attack_Damage(int);
// will automatically remove old
// actors from the stage and deallocate
void Set_Frame_Head(Augments::Head_Type);
void Set_Frame_Weapon(Augments::Weapon_Type);
void Set_Frame_Body(Augments::Body_Type);
Monster(Augments::Head_Type,
Augments::Weapon_Type,
Augments::Body_Type);
};
};
using PlMonster = Player::Monster;
#endif
monster.cpp
#include "stdafx.h"
#include "Monster.h"
#include "Augments.h"
#include "Angel.h"
void Player::Monster::Refresh(float dt) {
};
int Player::Monster::R_Max_Health() const { return max_health; }
int Player::Monster::R_Curr_Health() const { return curr_health; }
int Player::Monster::R_Attack_Damage() const { return attack_damage; }
Augments::Head* Player::Monster::R_Frame_Head() { return frame_head; }
Augments::Body* Player::Monster::R_Frame_Body() { return frame_body; }
Augments::Weapon* Player::Monster::R_Frame_Weapon() { return frame_weapon; }
void Player::Monster::Set_Max_Health(int x) { max_health = x; }
void Player::Monster::Set_Curr_Health(int x) { curr_health = x; }
void Player::Monster::Add_Curr_Health(int x) { curr_health += x; }
void Player::Monster::Set_Attack_Damage(int x) { attack_damage = x; }
void Player::Monster::Set_Frame_Head(Augments::Head_Type x) {
if ( frame_head != nullptr ) {
frame_head->Destroy();
delete frame_head;
frame_head = nullptr;
}
frame_head = new Augments::Head(x);
theWorld.Add(frame_head);
};
void Player::Monster::Set_Frame_Weapon(Augments::Weapon_Type x) {
if ( frame_weapon != nullptr ) {
theWorld.Remove(frame_weapon);
delete frame_weapon;
frame_weapon = nullptr;
}
frame_weapon = new Augments::Weapon(x);
theWorld.Add(frame_weapon);
};
void Player::Monster::Set_Frame_Body(Augments::Body_Type x) {
if ( frame_body != nullptr ) {
theWorld.Remove(frame_body);
delete frame_body;
frame_body = nullptr;
}
frame_body = new Augments::Body(x);
theWorld.Add(frame_body);
};
Player::Monster::Monster(Augments::Head_Type head,
Augments::Weapon_Type weapon,
Augments::Body_Type body) {
frame_body = nullptr;
frame_head = nullptr;
frame_weapon = nullptr;
Set_Frame_Body(body);
Set_Frame_Head(head);
Set_Frame_Weapon(weapon);
}
source.cpp
#include "stdafx.h"
#include "LD33.h"
#include "Angel.h"
int main ( ) {
Game::Initialize();
theWorld.StartGame();
theWorld.Destroy();
return 0;
}
Errors include things such as:
Error 43 error LNK2005: "public: int __thiscall Player::Monster::R_Attack_Damage(void)const " (?R_Attack_Damage#Monster#Player##QBEHXZ) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\source.obj ClientGame
Error 3 error LNK2005: "public: void __thiscall Player::Monster::Set_Frame_Body(enum Augments::Body_Type)" (?Set_Frame_Body#Monster#Player##QAEXW4Body_Type#Augments###Z) already defined in Augments.obj C:\Users\The Shire\Desktop\ludum_dare\ludumdare33\Code\ClientGame\LD33.obj ClientGame
And it pretty much states similar for every single function in Monster.
Sorry for just dumping a ton of code. I've been trying to debug it for awhile but couldn't come up with any reasonable solution. I have the include guards, I don't see any namespace conflicts, and everything that needs to be defined is outside of the header files. I can't find anything in augments.h that would be causing this. I also thought it might be the enums, but replacing them with just int did not work either.
I'm thinking it might be the order of the include files? hmm. Maybe there's somehow multiple source files somewhere but I would have no clue as to how. Any help?
Had included Monster.cpp in another header file on accident! Oops

"Use of undeclared identifier A"

Any ideas on what is causing this compile-time error?
Basic setup:
main.cpp
#include <iostream>
#include "GroupTheorizer.h"
int main()
{
// ...
functs::Adder<char> A; // error on this line
/ ...
return 0;
}
GroupTheorizer.h
#ifndef __GroupTheory__GroupTheorizer__
#define __GroupTheory__GroupTheorizer__
class GroupTheorizer
{
// definitions of members of a GroupTheorizer object
// ...
};
#endif /* defined(__GroupTheory__GroupTheorizer__) */
GroupTheorizer.cpp
#include "GroupTheorizer.h"
#include <set>
#include <iostream>
#include <limits>
#include <string>
// ... implementations of GroupTheorizer members
// ...
namespace functs
{
class Adder
{
private:
static const char symbol = '+';
public:
T operator() (const T & x, const T & y) const { return x + y; };
char getSymbol(void) const { return symbol; };
};
// other functors ...
// ...
}
I'm fairly certain I linked the files together correctly, so what could be the problem?
Looking at your implementation of Adder, it seems like you mean it to be a template but haven't written it as such.
You're only missing the template <typename T> line.
template <typename T>
class Adder
{
private:
static const char symbol = '+';
public:
T operator() (const T & x, const T & y) const { return x + y; };
char getSymbol(void) const { return symbol; };
};