几个错误C2146:语法错误:缺少';'在'*'之前,我没有找到任何东西。 [英] several Error C2146: syntax error : missing ';' before '*' , I didn't find anything.
问题描述
我正在从企业架构师(类图)生成这个c ++代码(头文件),并面临几个错误,如
1.错误C2146:语法错误:在第24行'*'之前缺少';'(已评论)
2.错误C2143:语法错误:在第27行的'&'之前缺少','(我评论了它。 )
我找不到这个有什么问题..
我是C ++的新手..
Hi,
I'm generating this c++ code(header file) from enterprise architect(class diagram) and facing several errors like
1. error C2146: syntax error : missing ';' before '*' on line 24 (Commented)
2. error C2143: syntax error : missing ',' before '&' on line 27 (I commented it out.)
I couldn't find what's wrong with this..
I'm new to C++..
#include "oss.h"
#include "asn1.h"
#if !defined(EA_A82413CF_73C9_4cd6_8B8B_1DB261A17DF0__INCLUDED_)
#define EA_A82413CF_73C9_4cd6_8B8B_1DB261A17DF0__INCLUDED_
class __seqof1 : public OssList
{
public:
typedef CareerEntry component;
__seqof1();
__seqof1(const __seqof1& prm1);
~__seqof1();
component * at(OssIndex prm1); // line 24
const component * at(OssIndex prm1) const;
__seqof1 * extract_after(OssIndex prm1, OssIndex prm2);
OssIndex insert_after(OssIndex prm1, const component& prm2); //line 27
OssIndex insert_after(OssIndex prm1, __seqof1* prm2);
int operator !=(const __seqof1& prm1) const;
__seqof1 & operator =(const __seqof1& prm1);
int operator ==(const __seqof1& prm1) const;
OssIndex prepend(const component& prm1);
OssIndex prepend(__seqof1* prm1);
int remove_after(OssIndex prm1);
int remove_front();
};
class BBCard
{
public:
typedef OssString name;
typedef OSS_UINT32 age;
typedef OssString position;
typedef __seqof1 career;
virtual ~BBCard();
BBCard();
BBCard(const BBCard& prm1);
BBCard(const name& prm1, BBCard::age prm2, const position& prm3, const career& prm4);
age & get_age();
BBCard::age get_age() const;
career & get_career();
const career & get_career() const;
name & get_name();
const name & get_name() const;
position & get_position();
const position & get_position() const;
int operator !=(const BBCard& prm1) const;
BBCard & operator =(const BBCard& prm1);
int operator ==(const BBCard& prm1) const;
void operator delete(void* ptr);
void * operator new(size_t size);
void set_age(BBCard::age prm1);
void set_career(const career& prm1);
void set_name(const name& prm1);
void set_position(const position& prm1);
private:
BBCard::age age_field;
BBCard::career career_field;
BBCard::name name_field;
BBCard::position position_field;
};
/**
* Specific PDU classes
*/
class BBCard_PDU : public ConcretePDU
{
public:
virtual ~BBCard_PDU();
BBCard_PDU();
const BBCard * get_const_data() const;
BBCard * get_data() const;
void set_const_data(const BBCard& d);
void set_data(BBCard& prm1);
protected:
OssTypeIndex get_index() const;
};
/**
* Control object class
*/
class bcas_Control : public OssControl
{
public:
virtual ~bcas_Control();
bcas_Control();
bcas_Control(const bcas_Control& prm1);
};
/**
* Universal PDU class
*/
class bcas_PDU : public UniversalPDU
{
public:
virtual ~bcas_PDU();
bcas_PDU();
BBCard * get_BBCard() const;
const BBCard * get_const_BBCard() const;
void set_BBCard(BBCard& prm1);
void set_const_BBCard(const BBCard& prm1);
};
/**
* Representation types
*/
class CareerEntry
{
public:
typedef OSS_UINT32 from;
typedef OSS_UINT32 to;
typedef OssString team;
virtual ~CareerEntry();
CareerEntry();
CareerEntry(const CareerEntry& prm1);
CareerEntry(CareerEntry::from prm1, CareerEntry::to prm2, const team& prm3);
CareerEntry(CareerEntry::from prm1, const team& prm2);
from & get_from();
CareerEntry::from get_from() const;
team & get_team();
const team & get_team() const;
to * get_to();
const to * get_to() const;
void omit_to();
int operator !=(const CareerEntry& prm1) const;
CareerEntry & operator =(const CareerEntry& prm1);
int operator ==(const CareerEntry& prm1) const;
void operator delete(void* ptr);
void * operator new(size_t size);
void set_from(CareerEntry::from prm1);
void set_team(const team& prm1);
void set_to(CareerEntry::to prm1);
int to_is_present() const;
private:
OSS_UINT32 bit_mask;
CareerEntry::from from_field;
CareerEntry::team team_field;
CareerEntry::to to_field;
};
#endif // !defined(EA_A82413CF_73C9_4cd6_8B8B_1DB261A17DF0__INCLUDED_)
推荐答案
那是因为你的CareerEntry
类在第一次使用时是未知的。
你应该使用前向声明而不是atypedef
:
That is because yourCareerEntry
class is unknown when used first.
You should use a forward declaration instead of atypedef
:
// Forward declaration
class CareerEntry;
class __seqof1 : public OssList
{
public:
// Remove this
// typedef CareerEntry component;
__seqof1();
__seqof1(const __seqof1& prm1);
~__seqof1();
CareerEntry * at(OssIndex prm1);
const CareerEntry * at(OssIndex prm1) const;
__seqof1 * extract_after(OssIndex prm1, OssIndex prm2);
OssIndex insert_after(OssIndex prm1, const CareerEntry& prm2);
// ...
};
class CareerEntry
{
// ...
};
使用 typedef
这里的样式很糟糕并且代码混淆。
Using typedef
s here is bad style and obfuscates the code.
如果没有看到包含的文件,很难猜到。但是,您至少在转发声明之前不能使用CareerEntry
类。
我的意思是,以下程序不正确:
Without seeing the included files, it is hard to guess. However, you cannot useCareerEntry
class before, at least, a forward declaration.
I mean, the following program is incorrect:
#include <iostream>
using namespace std;
class Foo
{
typedef Bar B;
B * b();
};
class Bar
{
};
Bar * Foo::b(){return new Bar();}
int main(){}
因缺少前瞻性声明。修复以下内容:
because of a missing forward declaration. The following one is fixed:
#include <iostream>
using namespace std;
class Bar; // class forward declaration
class Foo
{
typedef Bar B;
B * b();
};
class Bar
{
};
Bar * Foo::b(){return new Bar();}
int main(){}
这篇关于几个错误C2146:语法错误:缺少';'在'*'之前,我没有找到任何东西。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!