Sign in to follow this  
ajm113

Trying To Return A Struct Value

Recommended Posts

string sz_4343 = Var3f[(string)VariableList[sz_Count]]; VariableList is a char* array which stores names and sz_Count is a int that puts the number in the id of the name and Var3f is a struct object that stores 3 variables. float, int and char* and is supposed to get the information from the struct by entering a name id into it. But I get this error: Error 5 error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)

typedef int Var;

struct Var_r {
char  char3f;
float float3f;
int   int3f;
};



//typedef std::map<Var, Var_r> Variable_f;
typedef std::map<CAtlString, Var_r> Variable_f;

//keep the names of variables created
CAtlString VariableList [999];

Share this post


Link to post
Share on other sites
(string)VariableList[sz_Count]

You cannot cast char into string. That;s just naughty, and does many things you do not want to do.

Quote:
Error 5 error C2679: binary '[' : no operator found which takes a right-hand operand of type 'std::basic_string<_Elem,_Traits,_Ax>' (or there is no acceptable conversion)


This says exactly what the error is. Var_r has no subscript operator.

Quote:
Var3f is a struct object that stores 3 variables


From the rest of the context, Var3f is of type Variable_f;

In that case, the following might do it:

CAtlString sz_4343 = Var3f[VariableList[sz_Count]];


But there's lots of bad mojo here, including very confusing type and variable names.

Share this post


Link to post
Share on other sites
Well I get this error now.

Error 5 error C2440: 'initializing' : cannot convert from 'Var_r' to 'ATL::CStringT<BaseType,StringTraits>'

On That line you posted. I did try casting the Var3f on that line as a CstringT, but nether that worked.

Example of my code (If it helps)
I am also trying to avoid memory leaks, so I added a VarCount and a char array list of the names so when the program closes or reloads. Its going to use the number of arrays listed then go in a for loop and repeat the number VarCounts their are and and its going to get the varriable list array. By adding the current number we are on from the number of Vars to return the value of the array list. So I can get the data from the id and then delete it or erase it.

Var3f["idName"].char3f = "Value I entered";

Share this post


Link to post
Share on other sites
1. Create a int that holds number of vars.

2. Create a list of names of those vars in a char array.

3. Create a struct that uses chars instead of ints as a id that holds the values of the var in char, float or int format using map header.


The goal is its just like a Find and Replace Dialog, but it stores tons of keywords and values. So when I search a string when it finds $sz_var in that char its searching through.

Example of creating the var of my parser:

//p = char *
Var3f[p].char3f = NULL; //Entering Value into char id by map/struct Variable Name
VariableList[VarCount] = p;
VarCount++;





Trying To Replace Keywords:

Variable_f Var3f;

int sz_Count = 0;
for(int i=VarCount; i>-1; i--)
{

size_t i_mFound2;
int RB2; //First pos of $
int RE;

//Find $ Pos Area / Working On It


CAtlString sz_4343 = Var3f[VariableList[sz_Count]];

i_mFound2=sData.find((string)sz_4343);

sz_Count++;
}





[Edited by - ajm113 on July 3, 2008 4:36:38 PM]

Share this post


Link to post
Share on other sites
How is this a beginners question? If no one can figure out if I am write basically a complex find and replace functionality I am trying to write for chars?

I though beginners ask questions like "Why Do I Have To Learn C++"?

Share this post


Link to post
Share on other sites
Quote:
Original post by ajm113
How is this a beginners question? If no one can figure out if I am write basically a complex find and replace functionality I am trying to write for chars?

I though beginners ask questions like "Why Do I Have To Learn C++"?


The reason is probably because you have completely beginner mistakes in your code, like trying to arbitrarily cast incompatible objects:
Quote:
CAtlString sz_4343 = Var3f[VariableList[sz_Count]];
i_mFound2=sData.find((string)sz_4343);
You cannot cast a CAtlString into std::string. You can possibly convert between them, but not through cast.

For everything else, it's really hard to understand what types you have, and what the contents of some of the variables are supposed to be, or even what the function is supposed to do.

Share this post


Link to post
Share on other sites
Oh, I see. Sorry for not making much scenes their.

Uh, idk if it is the strings I have, but can mixing them up cause this error when my application completely close?

Unhandled exception at 0x0041be0d in Myapp.exe: 0xC0000005: Access violation writing location 0x00646c6e.

It just stops at

atlsimpstr.h on line 109.

Sorry for going off topic, but I can't figure what I am looking for exactly. I have been commenting out variables and code and using the VS2005 STD debbuger, but I don't understand what I am looking for and doing.

I would appreciate help with this really fast.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this