Error C2065: 'variable' : undeclared identifier on line of decleration of variable
Hello there,
I am making a form application with a serial interface. I am getting the "Error C2065: '_serialPort' : undeclared identifier on line of decleration of _serialPort.
How can the software complain that the identifier is not declared on the line where it is declared?
I tried to google the thing, but couldn't get a clear answer.
What is going on?
Code:
private: String^ sendData(String^ data) {
try {
String^ message;
// Create a new SerialPort object with default settings.
_serialPort = gcnew SerialPort();
// Allow the user to set the appropriate properties.
_serialPort->PortName = comboBox1->Text;
_serialPort->BaudRate = 9600;
_serialPort->Parity = Parity::None;
_serialPort->DataBits = 8;
_serialPort->StopBits = StopBits::One;
_serialPort->Handshake = Handshake::None;
// Set the read/write timeouts
_serialPort->ReadTimeout = 500;
_serialPort->WriteTimeout = 500;
_serialPort->Open();
_serialPort->WriteLine(data);
message = _serialPort->ReadLine();
_serialPort->Close();
}
catch (Win32Exception^ ex) {
MessageBox::Show(ex->Message);
}
return message;
}
Code:
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
using namespace System::IO::Ports;
Code:
#include "stdafx.h"
#include "Form1.h"
#using <System.dll>
#include "stdlib.h"
Thanks.
Kind regards,
Marius
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Please tell me how that could be. This is a VC++ question.
Thank you for your time.
Kind regards,
Marius
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Quote:
Originally Posted by
king.oslo
Please tell me how that could be. This is a VC++ question.
Thank you for your time.
Kind regards,
Marius
It's a managed C++/CLI question.
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Ok. I am afraid I didn't know that. My apologies . I am sorry.
How can we correct the mistake so that perhaps somebody will be able to help resolve the problem?Thanks.M
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Quote:
Originally Posted by
king.oslo
Ok. I am afraid I didn't know that. My apologies . I am sorry.
How can we correct the mistake so that perhaps somebody will be able to help resolve the problem?Thanks.M
You could repost your question in the managed C++ forum. Somebody there can likely help.
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Quote:
Originally Posted by
king.oslo
How can we correct the mistake so that perhaps somebody will be able to help resolve the problem?
Compiler Error C2065
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Quote:
Originally Posted by
king.oslo
I am getting the "Error C2065: '_serialPort' : undeclared identifier on line of decleration of _serialPort.
Code:
// Create a new SerialPort object with default settings.
_serialPort = gcnew SerialPort();
Is that what you call declaration?
It is not in C++ and not in managed C++.
Try:
Code:
SerialPort _serialPort = gcnew SerialPort();
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
Moved the thread into the managed forum.
With regard to the error...
Code:
private: String^ sendData(String^ data) {
try {
String^ message;
// Create a new SerialPort object with default settings.
_serialPort = gcnew SerialPort();
The convention of prepending a camel cased variable with an underscore ('_') implies that the variable is a class field. So you need to define _serialPort as a class field.
If you did not intend to make _serialPort a class variable, then drop the '_' and declare it inline.
Code:
// Create a new SerialPort object with default settings.
var serialPort = gcnew SerialPort();