public:
//{{AFX_DATA(CMy123View)
enum { IDD = IDD_MY123_FORM };
CMSComm m_ctrlComm;
然后在cpp文件中使用:
if(m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(FALSE);
结果报错:
: error C2065: 'm_ctrlComm' : undeclared identifier
: error C2228: left of '.GetPortOpen' must have class/struct/union type
我在H文件中#includes “mscomm.h”,在CPP文件中使用H文件中定义的标识符,为什么却得到未定义的报错呢?
10 个解决方案
#1
#include "MSComm.h" 在文件头添加这句
#2
我在H文件中#include'mscomm.h'
然后在吹泡泡文中包含了H文件的啊
应该不是这个原因吧
#3
同上
#4
#include 'mscomm.h' ?? 啥东西
你什么输入法 能把cpp打成吹泡泡 牛X
你什么输入法 能把cpp打成吹泡泡 牛X
#5
汗死,是#include "MSComm.h"
搜狗的输入法太雷人了。。
#6
另外,是#include "mscomm.h"
不过大小写没影响的,我试过都同样的报错
不过大小写没影响的,我试过都同样的报错
#7
对了,我不是用的对话框,而是FormView,这个有影响吗
#8
// 试试将 #include "MSCOMM.h"放到头文件的最上方。
#9
试了,还是一样的结果。。。我把代码说具体点,首先是H文件:
#include "mscomm.h"
#include "BtnST.h"
//{{AFX_INCLUDES()
//}}AFX_INCLUDES
#if !defined(AFX_123VIEW_H__6FD23064_CBFF_4AFA_B07F_CA204300B567__INCLUDED_)
#define AFX_123VIEW_H__6FD23064_CBFF_4AFA_B07F_CA204300B567__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMy123View : public CFormView
{
protected: // create from serialization only
CMy123View();
DECLARE_DYNCREATE(CMy123View)
public:
//{{AFX_DATA(CMy123View)
enum { IDD = IDD_MY123_FORM };
CButtonST m_btn_static;
CButtonST m_btn_redo;
CButtonST m_btn_undo;
CMSComm m_ctrlComm;
//}}AFX_DATA
// Attributes
...
...
然后是CPP文件:
void PortOpen()
{
/***********串口初始化**********************************/
if(m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(FALSE);
m_ctrlComm.SetCommPort(4);
if( !m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(TRUE);
else
AfxMessageBox("cannot open serial port");
m_ctrlComm.SetSettings("19200,n,8,1");
m_ctrlComm.SetInputMode(1);
m_ctrlComm.SetRThreshold(1);
m_ctrlComm.SetInputLen(0);
m_ctrlComm.GetInput();
}
error C2065: 'm_ctrlComm' : undeclared identifier
error C2228: left of '.GetPortOpen' must have class/struct/union type
error C2228: left of '.SetPortOpen' must have class/struct/union type
error C2228: left of '.SetCommPort' must have class/struct/union type
error C2228: left of '.GetPortOpen' must have class/struct/union type
error C2228: left of '.SetPortOpen' must have class/struct/union type
error C2228: left of '.SetSettings' must have class/struct/union type
error C2228: left of '.SetInputMode' must have class/struct/union type
error C2228: left of '.SetRThreshold' must have class/struct/union type
error C2228: left of '.SetInputLen' must have class/struct/union type
error C2228: left of '.GetInput' must have class/struct/union type
#10
我也遇到同样的问题了……我加入String头文件但是声明string字符串的时候就未定义标识符了……
#1
#include "MSComm.h" 在文件头添加这句
#2
我在H文件中#include'mscomm.h'
然后在吹泡泡文中包含了H文件的啊
应该不是这个原因吧
#3
同上
#4
#include 'mscomm.h' ?? 啥东西
你什么输入法 能把cpp打成吹泡泡 牛X
你什么输入法 能把cpp打成吹泡泡 牛X
#5
汗死,是#include "MSComm.h"
搜狗的输入法太雷人了。。
#6
另外,是#include "mscomm.h"
不过大小写没影响的,我试过都同样的报错
不过大小写没影响的,我试过都同样的报错
#7
对了,我不是用的对话框,而是FormView,这个有影响吗
#8
// 试试将 #include "MSCOMM.h"放到头文件的最上方。
#9
试了,还是一样的结果。。。我把代码说具体点,首先是H文件:
#include "mscomm.h"
#include "BtnST.h"
//{{AFX_INCLUDES()
//}}AFX_INCLUDES
#if !defined(AFX_123VIEW_H__6FD23064_CBFF_4AFA_B07F_CA204300B567__INCLUDED_)
#define AFX_123VIEW_H__6FD23064_CBFF_4AFA_B07F_CA204300B567__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
class CMy123View : public CFormView
{
protected: // create from serialization only
CMy123View();
DECLARE_DYNCREATE(CMy123View)
public:
//{{AFX_DATA(CMy123View)
enum { IDD = IDD_MY123_FORM };
CButtonST m_btn_static;
CButtonST m_btn_redo;
CButtonST m_btn_undo;
CMSComm m_ctrlComm;
//}}AFX_DATA
// Attributes
...
...
然后是CPP文件:
void PortOpen()
{
/***********串口初始化**********************************/
if(m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(FALSE);
m_ctrlComm.SetCommPort(4);
if( !m_ctrlComm.GetPortOpen())
m_ctrlComm.SetPortOpen(TRUE);
else
AfxMessageBox("cannot open serial port");
m_ctrlComm.SetSettings("19200,n,8,1");
m_ctrlComm.SetInputMode(1);
m_ctrlComm.SetRThreshold(1);
m_ctrlComm.SetInputLen(0);
m_ctrlComm.GetInput();
}
error C2065: 'm_ctrlComm' : undeclared identifier
error C2228: left of '.GetPortOpen' must have class/struct/union type
error C2228: left of '.SetPortOpen' must have class/struct/union type
error C2228: left of '.SetCommPort' must have class/struct/union type
error C2228: left of '.GetPortOpen' must have class/struct/union type
error C2228: left of '.SetPortOpen' must have class/struct/union type
error C2228: left of '.SetSettings' must have class/struct/union type
error C2228: left of '.SetInputMode' must have class/struct/union type
error C2228: left of '.SetRThreshold' must have class/struct/union type
error C2228: left of '.SetInputLen' must have class/struct/union type
error C2228: left of '.GetInput' must have class/struct/union type
#10
我也遇到同样的问题了……我加入String头文件但是声明string字符串的时候就未定义标识符了……