Multiple Redefinitions?

DialogSpec_H wrote:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once
#ifndef __INC__DIALOGSPEC
#define __INC__DIALOGSPEC
#include <string>
#include <sstream>

///////////////////////////////
//Contains dialog specific data
///////////////////////////////

//Dialog Commands
namespace Inc
{
	namespace Dialog
	{
		//Commands
		enum DialogCommand
		{
			//enum
		};

		//Dialog Command Structure
		struct DialogCmdInfo
		{
			//struct
		};

		//Convert DialogCmdInfo -> String
		bool DialogCmdInfoToString(const DialogCmdInfo& DCI, std::string& str)
		{
			//func
		}

		//Convert String -> DialogCmdInfo
		bool StringToDialogCmdInfo(const std::string& str, DialogCmdInfo& DCI)
		{
			//func
		}
	};
};

#endif 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <string>
#include "LoginDialog.h"
#include "DialogSpec.h"

void main()
{	
	CLoginDialog Diag;

	WaitForSingleObject(Diag.GetOutEvent(), INFINITE);
	Inc::Dialog::DialogCmdInfo DCI;
	DCI.Cmd = Inc::Dialog::SETNOTIFICATION;
	DCI.strInfo = "Haha!";
	std::string strCmd;
	Inc::Dialog::DialogCmdInfoToString(DCI, strCmd);
	Diag.AddDataIn(strCmd);
	std::cout << "Shutting Down...\n";
	std::cin.get();
}



Dialog Spec is included in main.cpp and LoginDialog.h only... where did i forget to prevent the multiple definitions?
Last edited on
By having the function body in the header, you're redefining the function in every source file that #includes it.

There are 3 solutions to this problem (listed in order of my recommendation):

1) Put only the prototypes in dialogspec.h, and put the function bodies in a seperate cpp file.

2) Make your functions inline

3) Make your functions static.

Topic archived. No new replies allowed.