Namespaces & "error C2059: syntax error : 'string'"

closed account (j6pf92yv)
REPOSTED THE PROBLEM BELOW WITH ALL SUGGESTED IMPROVEMENTS. STILL PROBLEMS THOUGH!

THANKS GUYS
Last edited on
1
2
3
4
5
6
7
8
enum eLogEntryType
{
	LOG_GENERAL = 0,
	LOG_WARNING,
	LOG_DEBUG,
	LOG_ALL,
};


Remove the comma after LOG_ALL
LOG_ALL,
closed account (j6pf92yv)
Thanks xandel33, but that hasn't cleared up the problem. I changed my enum to

1
2
3
4
5
6
7
enum eLogEntryType
{
	LOG_GENERAL = 0,
	LOG_WARNING,
	LOG_DEBUG,
	LOG_ALL
};


But theres still the same error appearing on compile
Can you post the entire compile error?

Just as a matter of good programming practice, never use a namespace in a header file. You should remove the

 
using namespace std;


from your header file and prefix everything that needs to be with std::.

closed account (j6pf92yv)
OK, I've tried to tidy this up to make it a bit clearer. I've implemented the suggestions above, but still no luck. The error is caused by the member definition:

utilities::CLogFile m_Log("global_log",LOG_ALL,1);
//returns - error C2059: syntax error : 'string'

Heres the header with the compiler error:
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
///////////////////////////////////////////////////////////////////////
// myConsoleApplication.h
///////////////////////////////////////////////////////////////////////

#pragma once

#include "CConsoleApplication.h"
#include "../Utilities/CLogFile.h"
#include "../Utilities/CTimer.h"

///////////////////////////////////////////////////////////////////////
// 
///////////////////////////////////////////////////////////////////////
class myConsoleApplication : public CConsoleApplication
{
	// add pre Main initialisation procedures
	DECLARE_INITIALISE;

	public:

		myConsoleApplication ();
		virtual ~myConsoleApplication ();	    
		virtual int Main (int iNumArgs, char** apcArgs);
		
	private:

		utilities::CLogFile m_Log("global_log",LOG_ALL,1);			
                //#######  - error C2059: syntax error : 'string'

		utilities::CTimer	 m_Timer;
};
///////////////////////////////////////////////////////////////////////

// implement the pre Main initialisation
REGISTER_INITIALISE(myConsoleApplication);


And heres a reduced class with zero functionality (but still the error)

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
43
44
45
46
47
48
///////////////////////////////////////////////////////////////////////
// CLogFile
///////////////////////////////////////////////////////////////////////

#pragma once

#include <list>
#include <string>
#include <fstream>
#include <ctime>

#include <cstdio>
#include <cstdarg>

// add to the utilities namespace
namespace utilities
{

///////////////////////////////////////////////////////////////////////

// types of valid log entry
enum eLogEntryType
{
	LOG_GENERAL = 0,
	LOG_WARNING,
	LOG_DEBUG,
	LOG_ALL
};


///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
class CLogFile
{
	///////////////////////////////////////////////////////////////////
	
	public:

		CLogFile(const char * csName, eLogEntryType eLogPolicy = LOG_ALL, unsigned int uiFlushSize = 30)
		{};
		
};
///////////////////////////////////////////////////////////////////////

} // close utilities namespace

/////////////////////////////////////////////////////////////////////// 


Is there a problem with my member defn?
Last edited on
You can't initialize m_Log like that. You need to initialize it in the constructor:
1
2
3
4
myConsoleApplication ()
    :m_log("global_log",LOG_ALL,1);
....
utilities::CLogFile m_log;


I hope this helps! ^_^

rpgfan
Last edited on
closed account (j6pf92yv)
Ahhhh ..... Initialization Lists(?) Never really used or paid any real attention to them in examples! Time to read up on them i think!

Thanks rpgfan and everyone else who offered advice. It's appreciated!

Doug
Yep, initialization lists. Just beware of them when you play with virtual inheritance. They come back to bite you. ;)
Topic archived. No new replies allowed.