Error trying to pass an std::vector<unsigned char>

B

Bobrick

Hi.

Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.

char temp;
std::vector<unsigned char> mmessage;

while (!done){
mmessage = midiin->Getmidi();
temp = mmessage[1];
textBox1->Text = temp.ToString();
done = true;
}


GetMidi is a function which returns an std::vector<unsigned char>, the
code for which is:

std::vector<unsigned char> RtMidiIn :: Getmidi(void)
{
double stamp;
std::vector<unsigned char> message;
RtMidiIn *midiin = 0;

stamp = midiin->getMessage( &message );
return message;
}

And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?
 
V

Victor Bazarov

Bobrick said:
Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.

char temp;
std::vector<unsigned char> mmessage;

while (!done){
mmessage = midiin->Getmidi();
temp = mmessage[1];
textBox1->Text = temp.ToString();
done = true;
}

Your indentation skills leave a lot to be desired. Try to always use
spaces. And the same number of them for the lines in the same block.
GetMidi is a function which returns an std::vector<unsigned char>, the
code for which is:

std::vector<unsigned char> RtMidiIn :: Getmidi(void)
{
double stamp;
std::vector<unsigned char> message;
RtMidiIn *midiin = 0;

stamp = midiin->getMessage( &message );

Undefined behaviour. You're dereferencing a null pointer here. And
you didn't say what 'getMessage' is (or how it's declared).

Is it possible you have an extraneous '&' before the "message" here?
return message;
}

And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?

Have you tried the online help? Put the cursor on the error code
and press F1... And if it's still confusing, complain to Microsoft.

V
 
C

Colander

Hi,

Hi.

Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.

char temp;
std::vector<unsigned char> mmessage;

while (!done){
mmessage = midiin->Getmidi();
temp = mmessage[1];
textBox1->Text = temp.ToString();
done = true;
}

GetMidi is a function which returns an std::vector<unsigned char>, the
code for which is:

std::vector<unsigned char> RtMidiIn :: Getmidi(void)
{
double stamp;
std::vector<unsigned char> message;
RtMidiIn *midiin = 0;

stamp = midiin->getMessage( &message );
return message;

}And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?

My first guess (If you got the line correct) is that the compiler can't
find
Getmidi(), so it assumes it exists (to link later) and assumes it
returns and int.
The latter of the assumtions is incorrect, and therefor it can't bind
the return
type to the variable. If your declare the function before using it
atleast
this error will vanish.

(You should have a warning about that....)

Furthermore, there are a lot of different problems with this code,
the char type doesn't have any member function, not even ToString();
And "RtMidiIn *midiin = 0;" makes midiin point to nothing, you can't
call a member function from an instance that's not existing....

Did you get the warning about assuming a functions that returns an int?
 
M

Mike Wahler

Bobrick said:
Hi.

Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.

char temp;
std::vector<unsigned char> mmessage;

while (!done){
mmessage = midiin->Getmidi();
temp = mmessage[1];

Note that this assumes that the vector 'nmessage' contains at least two
elements.
Also note that you're assigning an unsigned char to a char. The destination
might not have the range necessary to represent the unsigned char value.
textBox1->Text = temp.ToString();

Above, you define 'temp' as type 'char'. Type 'char'
does not have member functions. You don't show what
'textBox1's type is, so I cannot comment on that.
done = true;
}


GetMidi is a function which returns an std::vector<unsigned char>, the
code for which is:

std::vector<unsigned char> RtMidiIn :: Getmidi(void)
{
double stamp;
std::vector<unsigned char> message;
RtMidiIn *midiin = 0;

stamp = midiin->getMessage( &message );

'midiin' is a pointer with a NULL value. Dereference of it
produces undefined behavior.
return message;
}

And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?

I don't see anything in what you posted that I would think would
cause the error message you cite. It appears that the compiler
thinks you're trying to assign a type 'int' object to a type
'std::vector<>' object, but I don't see you doing that in this
code. It would be better if you'd put together a small, but
complete program which reproduces the error message.

-Mike
 
J

Jim Langston

Bobrick said:
Hi.

Thanks to everyone who replied to my last post, it turns out it wasn't
the line where I was trying to treat the variable in question as an
array which was the problem, but the line above.

char temp;
std::vector<unsigned char> mmessage;

while (!done){
mmessage = midiin->Getmidi();
temp = mmessage[1];
textBox1->Text = temp.ToString();
done = true;
}


GetMidi is a function which returns an std::vector<unsigned char>, the
code for which is:

std::vector<unsigned char> RtMidiIn :: Getmidi(void)
{
double stamp;

Why are you declaring stamp when you never use it's value?
std::vector<unsigned char> message;
RtMidiIn *midiin = 0;

We are already inside the RtMidiIn class in a method. Why are you declaring
a pointer to the same class and initilializing it to 0?
stamp = midiin->getMessage( &message );

1. You are not using stamp so why assign it? So it would become
midiin->getMessage( &message );

2. Why are you using a null pointer to an unitialized instance? Don't you
want to use the current instance? So it would become:
getMessage( &message );

3. Why are you using &message? I'm presuming getMessage receives a
reference to a std::vector<unsigned char>, you don't need to (and it is
wrong) to preeceed it with & so it will become:
getMessage( message );

That is probably what you want to use.
return message;
}

And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?
 
M

Mike Wahler

Colander said:
Hi,

}And the error message I recieve is:

error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]

Can anyone explain in less confusing terms what this error means?

My first guess (If you got the line correct) is that the compiler can't
find
Getmidi(), so it assumes it exists (to link later) and assumes it
returns and int.

Since C++ does not allow implicit int return type, I would think that
if that were the case, we'd get an error indicating the function
not being declared.
Did you get the warning about assuming a functions that returns an int?

I don't know which version of VC++ the OP is using, but when I submit
the following code to VC++ 2005 Express Edition:

int main()
{
foo();
return 0;
}

It complains:

error C3861: 'foo': identifier not found

OP needs to supply more complete code.

-Mike
 
C

Colander

}And the error message I recieve is:
error C2679: binary '=' : no operator found which takes a right-hand
operand of type 'int' (or there is no acceptable conversion)
C:\Program Files\Microsoft Visual Studio
8\VC\include\vector(549): could be 'std::vector<_Ty>
&std::vector<_Ty>::eek:perator =(const std::vector<_Ty> &)'
with
[
_Ty=unsigned char
]
while trying to match the argument list '(std::vector<_Ty>,
int)'
with
[
_Ty=unsigned char
]
Can anyone explain in less confusing terms what this error means?
My first guess (If you got the line correct) is that the compiler can't
find
Getmidi(), so it assumes it exists (to link later) and assumes it
returns and int.Since C++ does not allow implicit int return type, I would think that
if that were the case, we'd get an error indicating the function
not being declared.
Did you get the warning about assuming a functions that returns an int?I don't know which version of VC++ the OP is using, but when I submit
the following code to VC++ 2005 Express Edition:

int main()
{
foo();
return 0;

}It complains:

error C3861: 'foo': identifier not found

OP needs to supply more complete code.

You are totally correct, btw the op is using version 8, and that give's
indeed an error,
so my guess is wrong, but it was the only thing about an int I could
think of and reading
the code he could have used every non-standard c++ tool out there, so I
figured, let's
ask....

And vs8 goes even further;
error C3861: 'foo': identifier not found
error C2365: 'foo' : redefinition; previous definition was 'formerly
unknown identifier'

(If you backward-declare foo)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,888
Messages
2,569,964
Members
46,294
Latest member
HollieYork

Latest Threads

Top