CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 13 of 13
  1. #1
    Join Date
    Dec 2009
    Posts
    17

    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.

  2. #2
    Join Date
    Dec 2009
    Posts
    17

    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"

  3. #3
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Exclamation 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)

  4. #4
    Join Date
    Dec 2009
    Posts
    17

    Cool 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

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Beginner's problem

    Quote Originally Posted by o00o View Post
    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?

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    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...

  7. #7
    Join Date
    Dec 2009
    Posts
    17

    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

  8. #8
    Join Date
    Apr 2009
    Location
    Cochin
    Posts
    83

    Smile 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)

  9. #9
    Join Date
    Apr 2008
    Posts
    725

    Re: Beginner's problem

    Quote Originally Posted by o00o View Post

    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

  10. #10
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Beginner's problem

    Quote Originally Posted by Amleto View Post
    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...

  11. #11
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Beginner's problem

    Quote Originally Posted by o00o View Post
    @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...

  12. #12
    Join Date
    Apr 2008
    Posts
    725

    Re: Beginner's problem

    Quote Originally Posted by VladimirF View Post
    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

  13. #13
    Join Date
    Dec 2009
    Posts
    17

    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
  •  





Click Here to Expand Forum to Full Width

Featured