-
December 16th, 2009, 05:19 AM
#1
Beginner's problem
Hi
Not sure if I should ask my question here, so admin please move it to the appropriate section. Sorry for the trouble.
I'm coding using VS6. I wanted to create a method that will return a user-defined struct.
This is found in the header file.
class A
{
protected :
typedef struct {
int a;
int b;
} B;
B NAHD_Match::ABC(const char *name1);
}
It compiles fine if I don't use the method ABC in the source code.
However, when I try to insert code for
A::ABC(const char *name1)
in the source code to the following
B A::ABC(){
B newB;
newB.a=99;
newB.b=45;
return newB;
}
the compiler pops the following error message.
D:\Shared Documents\Work Docs\A.cpp(72) : error C2143: syntax error : missing ';' before 'tag::id'
D:\Shared Documents\Work Docs\A.cpp(72) : error C2501: 'B' : missing storage-class or type specifiers
D:\Shared Documents\Work Docs\A.cpp(72) : fatal error C1004: unexpected end of file found
palmprintDlg.cpp
And when I change the return type to int, the code will compile successfully. The actual full code isn't written by me and I was task to check some of the implementations only so I would try not to include the entire code here unless really needed.
The include message if needed, contains
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include "A.h"
Do let me know where did I do wrong?
Thanks in advance.
-
December 16th, 2009, 05:23 AM
#2
Re: Beginner's problem
I realised I didn't manage to replace all the words correctly and there's no edit button for me to correct the mistake...
so please note that all "NAHD_Match "was replaced by "A"
-
December 16th, 2009, 07:13 AM
#3
Re: Beginner's problem
You must terminate the closing braces of a class with ';' (semicolon).
"I studied everything but never topped. Today, toppers of the world's best universities are my employees"
-William Henry Gates (Bill Gates)
-
December 16th, 2009, 03:56 PM
#4
Re: Beginner's problem
hi, thanks for the quick reply =P
In the actual code, there is actually a ";". So even if i add in the ";", the same problem still persist. I read in some other post about c++ not being able to recognize the struct or something similar. Which explains why when I replace the method with a data type such as int, the method will work?
Thanks in advance again
-
December 16th, 2009, 03:59 PM
#5
Re: Beginner's problem
Originally Posted by o00o
hi, thanks for the quick reply =P
In the actual code, there is actually a ";". So even if i add in the ";", the same problem still persist. I read in some other post about c++ not being able to recognize the struct or something similar. Which explains why when I replace the method with a data type such as int, the method will work?
Thanks in advance again
How is anybody supposed to help if you don't post your actual code?
-
December 16th, 2009, 04:28 PM
#6
Re: Beginner's problem
Since struct B is defined inside your class A, do this:
Code:
A::B A::ABC(const char *name1)
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...
-
December 16th, 2009, 11:57 PM
#7
Re: Beginner's problem
@GCDEF
Well, one part of the reason is because the code belongs to someone else and another is the code is really very very long. I can send you the 2 files (source + header) individually through a email though.
@VladimirF
I got this error instead when I try this. It seems the compiler thinks that A::B is a method instead?
D:\Shared Documents\Work Docs\FYP\FYP_cyl\NAHD_Match.cpp(72) : error C2511: 'ABC' : overloaded member function 'A::B (void)' not found in 'A'
Thanks in advance =D
-
December 17th, 2009, 04:19 AM
#8
Re: Beginner's problem
Well, one part of the reason is because the code belongs to someone else and another is the code is really very very long. I can send you the 2 files (source + header) individually through a email though.
He was asking you to post the 'exact' block of codes in your program., not your entire source code.
"I studied everything but never topped. Today, toppers of the world's best universities are my employees"
-William Henry Gates (Bill Gates)
-
December 17th, 2009, 11:55 AM
#9
Re: Beginner's problem
Originally Posted by o00o
class A
{
protected :
typedef struct {
int a;
int b;
} B;
B NAHD_Match::ABC(const char *name1);
}
It compiles fine if I don't use the method ABC in the source code.
However, when I try to insert code for
A::ABC(const char *name1)
in the source code to the following
B A::ABC(){
B newB;
newB.a=99;
newB.b=45;
return newB;
}
see red bits
-
December 17th, 2009, 01:11 PM
#10
Re: Beginner's problem
Originally Posted by Amleto
see red bits
I think it has been established that the code in original post is somewhat “approximate”.
Well, even the function name doesn’t match!
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...
-
December 17th, 2009, 01:17 PM
#11
Re: Beginner's problem
Originally Posted by o00o
@VladimirF
I got this error instead when I try this. It seems the compiler thinks that A::B is a method instead?
D:\Shared Documents\Work Docs\FYP\FYP_cyl\NAHD_Match.cpp(72) : error C2511: 'ABC' : overloaded member function 'A::B (void)' not found in 'A'
Wait! (void)? Your definition of that function has one parameter.
Anyway, this is different error (from the original one, that is fixed by specifying that return type B is defined in class A).
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...
-
December 18th, 2009, 05:26 PM
#12
Re: Beginner's problem
Originally Posted by VladimirF
I think it has been established that the code in original post is somewhat “approximate”.
Well, even the function name doesn’t match!
yeah, but it was still relevent for his reported error in post #7
-
December 19th, 2009, 01:39 AM
#13
Re: Beginner's problem
Well, i think I've solved the problem...
It's because I (or rather the original writer) used typedef in the header file...
I hope that is the reason behind the problem really... >.<
Thanks everyone for the input
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
|