dimanche 29 mai 2016

Variable in Parentheses C++

I am currently in the process of writing up a C++ program that randomly chooses roles for people using file input/output.

I am almost done, and I build often to make sure my code is working and not psuedocode. I received an error on my snippet of code -

randomPrefs.open ("Preferences/"members[random]"-Preferences");

I am trying to access the text file in Preferences/foo-Preferences, and the variable is made random by some code above it. I have couted the random snippet and it works perfectly, so I need not include it here. The error I get is :

Avalon - Omnipotent.cpp:61:21: error: unable to find string literal operator 'operator""members' with 'const char [13]', 'unsigned int' arguments

And so, I have searched around for this error but have found nothing. I thought of making a mini-parentheses around it, and it resulted in a different error - Avalon - Omnipotent.cpp:61:51: error: expression cannot be used as a function

Any help would be appreciated.

A little note down here, when not having the parentheses around it, I get a warning about my variable not being used -

Avalon - Omnipotent.cpp:39:21: warning: unused variable 'members' [-Wunused-variable]

However, the second error does not give a warning about the unused variable.

Hey is what my variable looks like:

 unsigned const char members[22] = 

And I assigned the value "random" which selects a random number from 0 - 21 and I assign the number generated to value random, and declare the variable as members[random]. It works perfectly, I just need help with these errors.

Help!




Aucun commentaire:

Enregistrer un commentaire