Jump to content
  • Advertisement
Sign in to follow this  
kerilynne

Unresolved externals, using statics, for singletons

This topic is 3883 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okay, so I just pumped this code out in the last 3 hours, no compiler errors except for unresolved externals, I'll post the code: Game_Settings.h
#ifndef GAME_SETTINGS_H
#define GAME_SETTINGS_H
#include "Resource_Manager.h"
#include "Options.h"
#include "Linked_List.h"

class Settings
{
public:
	Settings(){};
	friend class Card_Game;

	void display_options()
	{
		option_list.display_list();
	}
	void add_option(Option * option)
	{
		m_rOptions.manage_resource(option->name(), &(option) );
		if(option->internal_setting == false)
		{
			option_list.add_node(option->name());
		}
	}

	Linked_List<std::string> option_list;
	Resource_Manager<Option*> m_rOptions;
};

class Blackjack_Settings : public Settings
{
public:
	Blackjack_Settings()
	{
		add_option(Betting::get_option());
		add_option(Minimum_Bet::get_option());
		add_option(All_Bets_on_House::get_option());
		add_option(Reload_Players::get_option());
	}
};
#endif


Options.h
#ifndef OPTIONS_H
#define OPTIONS_H
struct Option
{	
friend class Settings;
public:
	virtual void toggle();
	std::string name(){return option_name;}
	std::string option_name;
	bool internal_setting;

protected:	
	Option(){};
};

////////In order from top to bottom/////////

/*
Setting for the Minimum Bet
Internal setting for house betting only
Internal setting for reloading players
Setting for betting on/off
*/

struct Minimum_Bet : public Option
{
public:
	void toggle(int min_bet)
	{
		minimum_bet = min_bet;
	}
	static Minimum_Bet * Minimum_Bet::get_option()
	{
		return &option;
	}
private:
	static Minimum_Bet option;
	int minimum_bet;
protected:	
	Minimum_Bet()
	{
		option_name = "Minimum Bet";
		internal_setting = false;
	}

};

struct All_Bets_on_House : public Option
{
public:
	void toggle(bool true_false)
	{
		all_bets_on_house = true_false;
	}
	static All_Bets_on_House * All_Bets_on_House::get_option()
	{
		return &option;
	}
private:
	static All_Bets_on_House option;
	bool all_bets_on_house;
protected:
	All_Bets_on_House()
	{
		option_name = "All bets on house";
		internal_setting = true;
	}
};

struct Reload_Players : public Option
{
public:
	void toggle(bool true_false)
	{
		reload_players = true_false;
	}
	static Reload_Players * Reload_Players::get_option()
	{
		return &option;
	}
private:
	bool reload_players;
	static Reload_Players option;
protected:	
	Reload_Players()
	{
		option_name = "Reload Players";
		internal_setting = true;
	}

};

struct Betting : public Option
{
public:
	void toggle(bool true_false)
	{
		betting_toggle = true_false;
	}
	static Betting * Betting::get_option()
	{
		return &option;
	}
private:
	bool betting_toggle;
	static Betting option;	
protected:	
	Betting()
	{
		option_name = "All bets on house";
		internal_setting = true;
	}
};
#endif


Here are the errors I'm getting :) Main.obj : error LNK2001: unresolved external symbol "private: static struct Minimum_Bet Minimum_Bet::option" (?option@Minimum_Bet@@0U1@A) Main.obj : error LNK2001: unresolved external symbol "private: static struct All_Bets_on_House All_Bets_on_House::option" (?option@All_Bets_on_House@@0U1@A) Main.obj : error LNK2001: unresolved external symbol "private: static struct Reload_Players Reload_Players::option" (?option@Reload_Players@@0U1@A) Main.obj : error LNK2001: unresolved external symbol "private: static struct Betting Betting::option" (?option@Betting@@0U1@A) To be quite honest, I have no idea what I can change to fix this, I know I'm probably misusing statics in some way, maybe I need some schoolin from all you smart programmers out there :) [Edited by - kerilynne on February 6, 2008 4:23:53 PM]

Share this post


Link to post
Share on other sites
Advertisement
Can you add line breaks to your error messages so that we don't have to scroll back forth to read your code? (Depending on screen resolution of course...)

As for your errors, it looks like maybe you're declaring static member variables, but not defining them anywhere (typically this is done in the .cpp file associated with the class).

Share this post


Link to post
Share on other sites
Quote:

As for your errors, it looks like maybe you're declaring static member variables, but not defining them anywhere (typically this is done in the .cpp file associated with the class).


I believe this is the problem, because there isn't a CPP file implemented for Options.h!!

Share this post


Link to post
Share on other sites
That did solve the problem, here is what I did in my Options.cpp file:


#include "stdafx.h"
#include "Options.h"

Minimum_Bet Minimum_Bet::option;
All_Bets_on_House All_Bets_on_House::option;
Reload_Players Reload_Players::option;
Betting Betting::option;


But now I have a nasty boost checked_delete problem.

It might be the fact that I'm using statics and pushing them into an std::map which uses boost.

Here is the boost source causing the error:


// verify that types are complete for increased safety

template<class T> inline void checked_delete(T * x)
{
// intentionally complex - simplification causes regressions
typedef char type_must_be_complete[ sizeof(T)? 1: -1 ];
(void) sizeof(type_must_be_complete);
delete x;
}



I'm reading the documentation on it now.

Can anyone help me make sense of this?

Quote:

The header <boost/checked_delete.hpp> defines two function templates, checked_delete and checked_array_delete, and two class templates, checked_deleter and checked_array_deleter.

The C++ Standard allows, in 5.3.5/5, pointers to incomplete class types to be deleted with a delete-expression. When the class has a non-trivial destructor, or a class-specific operator delete, the behavior is undefined. Some compilers issue a warning when an incomplete type is deleted, but unfortunately, not all do, and programmers sometimes ignore or disable warnings.

A particularly troublesome case is when a smart pointer's destructor, such as boost::scoped_ptr<T>::~scoped_ptr, is instantiated with an incomplete type. This can often lead to silent, hard to track failures.

The supplied function and class templates can be used to prevent these problems, as they require a complete type, and cause a compilation error otherwise.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!