Quantcast
Channel: Visual C forum
Viewing all articles
Browse latest Browse all 15302

WCHAR, wstring, declaring and getting access

$
0
0

Visual Studio 2008, C++

Class C_AR2_Messages processes the data and class C_Configuration_Manager reads a configuration file and performs the setup.  The configuration manager must access data within the messages class. 

I am unable to copy/paste from the work computer to here and must type everything in.  Please try to accommodate any obvious typos.

Include file Message_Constants.h contains

Message_Constants.h contains
Const unsigned int MAX_PARAMETER_NAME_LENGTH = 34;
Const unsigned int COMMON_ARRAY_SIZE  = COMMON_OMEGA_DECOM_STATUS + 1;
// The value of COMMON_ARRAY_SIZE is 18.


The messages class contains:

Class C_AR2_Messages { … WCHAR m_common_parameter_names _NAMES[ COMMON_ARRAY_SIZE ][ MAX_PARAMETER_NAME_LENGTH ];

All the below fail compile but to me, they match the examples I have found in my searches. Two of them claim that the open brace is a syntax error. WCHAR m_test[ ] [ ] = { {L”one”}, { L”two” }, { L”three” } }; WCHAR m_test_2[ 3 ] [8 ] = { {L”one”}, { L”two” }, { L”three” } }; Wstring m_test_3[ ] = { L”one”, L”two”, L”three” };

The ability to initialize an array of strings/WCHAR/wchar_t would be a major asset. I don't know what is wrong with these declarations. 

Moving on and referencing the first declaration, from C_Configuration_Manager dot H

Class C_Configuration_Manager
{ …	
VOID  Set_Common_Names_Pointer( WCHAR  *new_pointer[COMMON_ARRAY_SIZE  ][ MAX_PARAMETER_NAME_LENGTH ] );
WCHAR mp_common_parameter_names[COMMON_ARRAY_SIZE  ][ MAX_PARAMETER_NAME_LENGTH ];

The above is a method to received a pointer to the strings from the messages and the pointer itself.  The code is defined in C_Configuration_Manager.cpp

VOID  Set_Common_Names_Pointer( WCHAR  *new_pointer[COMMON_ARRAY_SIZE  ][ MAX_PARAMETER_NAME_LENGTH ] )
{ mp_common_parameter_names = new_pointer; }

The compiler does not accept that saying:

Error C2440: ‘=’ cannot convert from WCHAR *[] [34] to ‘WCHAR *[18][34]

I don't know where or why it gets the [] before the [34]. The one constant is used in all declarations.

Having failed on those two fronts I tried adding this

Class C_AR2_Messages
{ …
friend class C_Configuration_Manager;

In the hopes of giving the configuration manager direct access. In that configuration code was added to see if C_Configuration_Manager could access the member variables of C_AR2_Messages:

wstring test1 = m_common_parameter_names[ 0 ] [ 0 ];
wstring test1 = C_AR2_Messages::m_common_parameter_names[ 0 ] [ 0 ];
Both of which fail the compile.
I am hoping somenone will show me the error of my ways on one or more of these three errors.

Just for a summary:  There is an array of 18 parameter names in C_AR2_Messages.  Class C_Configuration_Manager needs to have read/write access to them.  The ability to initialize those strings at compile time would be very nice.


~jag77 We need to know what a dragon is before we study its anatomy. (Bryan Kelly, 2010)




Viewing all articles
Browse latest Browse all 15302

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>