compilation error... Am I missing anything?

S

smilesonisamal

class A
{
public:
void SetA(EmployeeCategory a); // EmployeeCategory is a enum
and is already declared.
EmployeeCategory GetA() const;

private :
EmployeeCategory m_emplCategory; // This is initialized in the
constructor

}

In .cpp file
--------------
EmployeeCategory A::GetA() const
{
return m_emplCategory;

}

Set function works fine. But when I try to return a value for enum I
get the following error:
error C2511: ' EmployeeCategory A::GetA() const' : overloaded member
function not found in 'A'

I dont understand why this problem comes.

The following code works:

A: GetA(EmployeeCategory *eCat)
{

*eCat = m_emplCategory;

}

Is this a bug in the Visual Studio or I am missing anything?

Regards
Soni
 
A

Alf P. Steinbach

* (e-mail address removed):
class A
{
public:
void SetA(EmployeeCategory a); // EmployeeCategory is a enum
and is already declared.

I wonder what made you decide that that declaration could be totally irrelevant?

EmployeeCategory GetA() const;

private :
EmployeeCategory m_emplCategory; // This is initialized in the
constructor

}

In .cpp file
--------------
EmployeeCategory A::GetA() const
{
return m_emplCategory;

}

Set function works fine. But when I try to return a value for enum I
get the following error:
error C2511: ' EmployeeCategory A::GetA() const' : overloaded member
function not found in 'A'

I dont understand why this problem comes.

Because at that point you don't have anything named EmployeeCategory.

The following code works:

No it does not.
A: GetA(EmployeeCategory *eCat)

Here you have a syntax error, hence the code cannot "work" in any sense.

{

*eCat = m_emplCategory;

}

Is this a bug in the Visual Studio or I am missing anything?

The latter.

A few times. :)

Summing up: you have decided to (A) *not* provide the relevant information for
your problem, namely the declaration of EmployeeCategory (but all right, we old
hands understand from the problem that it's within the class or a base class,
but you could not know that we'd be familiar with your problem) and you have
decided to (B) instead provide some *incorrect*, misleading information, which
is very very counter-productive: it simply doesn't make sense to try to send
those you ask for help, on a wild goose chase.

Is that intentional, or?

If it's not intentional, then please read the FAQ's guidelines on how to post
(Google for "C++ FAQ Lite").




Cheers & hth.,

- Alf
 
S

smilesonisamal

* (e-mail address removed):


I wonder what made you decide that that declaration could be totally irrelevant?










Because at that point you don't have anything named EmployeeCategory.


No it does not.




Here you have a syntax error, hence the code cannot "work" in any sense.



The latter.

A few times. :)

Summing up: you have decided to (A) *not* provide the relevant information for
your problem, namely the declaration of EmployeeCategory (but all right, we old
hands understand from the problem that it's within the class or a base class,
but you could not know that we'd be familiar with your problem) and you have
decided to (B) instead provide some *incorrect*, misleading information, which
is very very counter-productive: it simply doesn't make sense to try to send
those you ask for help, on a wild goose chase.

Is that intentional, or?

If it's not intentional, then please read the FAQ's guidelines on how to post
(Google for "C++ FAQ Lite").

Cheers & hth.,

- Alf

sorry my mistake I missed void. But the code works if I pass as a
pointer. I have tried it. The EmployeeCategory is in a separate header
file. Not only enum even the following doesnot work. Iam using
Microsoft Visual C++ 2005 edition.

//in .h file
class A {
public:
void SetA(long x);
long GetA() const;

private:
long a;

};

//In .cpp file
-------------
A :: A()
{
a = 0;

}

A:: SetA(long b)
{
a = b;

}

long
A:: GetA() const
{
return a; // a is a private member of class A of type long.
}


Could you please help me in this regard?

Regards
Soni
 
A

Alf P. Steinbach

* (e-mail address removed):
sorry my mistake I missed void.

you also missed the advice about reading the faq, which in the part where it
talks about how to post says a few things about quoting

But the code works if I pass as a
pointer. I have tried it. The EmployeeCategory is in a separate header
file.

all right, same problem different cause then

just include that header from your .h file

Not only enum even the following doesnot work. Iam using
Microsoft Visual C++ 2005 edition.

//in .h file
class A {
public:
void SetA(long x);
long GetA() const;

private:
long a;

};

//In .cpp file
-------------
A :: A()
{
a = 0;

}

A:: SetA(long b)

missing result type

{
a = b;

}

long
A:: GetA() const
{
return a; // a is a private member of class A of type long.
}


hth.,

- alf
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top