-
August 2nd, 2013, 08:16 PM
#1
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
-
August 2nd, 2013, 08:23 PM
#2
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
-
August 2nd, 2013, 08:37 PM
#3
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
-
August 2nd, 2013, 08:43 PM
#4
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
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.
-
August 2nd, 2013, 08:58 PM
#5
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
Last edited by king.oslo; August 2nd, 2013 at 09:06 PM.
-
August 3rd, 2013, 06:52 AM
#6
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
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.
-
August 4th, 2013, 09:38 AM
#7
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
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
Best regards,
Igor
-
August 5th, 2013, 03:11 PM
#8
Re: Error C2065: 'variable' : undeclared identifier on line of decleration of variabl
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();
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
August 5th, 2013, 03:58 PM
#9
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();
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|