Getting an Errror ...

Discussion in 'C++' started by pai, Jun 28, 2006.

  1. pai

    pai Guest

    #include<iostream.h>

    struct ab{
    int a;
    };

    template <class T>
    class A{

    struct ab * ret_1();

    public:
    A();
    void disp();
    void ret();

    };

    template <class T>
    void A<T>::ret(){

    struct ab* b;
    b=ret_1();

    return b;
    }

    template <class T>
    struct ab * A<T>::ret_1(){

    struct ab* b;
    b=new (struct ab);

    return b;

    }

    template<class T>
    A<T>::A(){

    cout << "A const" ;

    }

    template <class T>
    void A<T>::disp(){
    cout << "disp" << endl;
    }

    int main(){
    A<int> a;
    a.disp();

    return 0;
    }

    *******************************************
    --------------------Configuration: test - Win32
    Debug--------------------
    Compiling...
    test.cpp
    C:\Pai\c++\linked-list\test.cpp(28) : error C2989: 'ab' : template
    class has already been defined as a non-template class
    C:\Pai\c++\linked-list\test.cpp(3) : see declaration of 'ab'
    C:\Pai\c++\linked-list\test.cpp(28) : error C2143: syntax error :
    missing ';' before '*'
    C:\Pai\c++\linked-list\test.cpp(28) : error C2065: 'T' : undeclared
    identifier
    C:\Pai\c++\linked-list\test.cpp(28) : error C2955: 'A' : use of class
    template requires template argument list
    C:\Pai\c++\linked-list\test.cpp(16) : see declaration of 'A'
    C:\Pai\c++\linked-list\test.cpp(28) : error C2501: 'ret_1' : missing
    storage-class or type specifiers
    C:\Pai\c++\linked-list\test.cpp(28) : error C2556: 'int *__thiscall
    A::ret_1(void)' : overloaded function differs only by return type from
    'struct ab *__thiscall A<T>::ret_1(void)'
    C:\Pai\c++\linked-list\test.cpp(10) : see declaration of
    'ret_1'
    C:\Pai\c++\linked-list\test.cpp(28) : error C2371: 'ret_1' :
    redefinition; different basic types
    C:\Pai\c++\linked-list\test.cpp(10) : see declaration of
    'ret_1'
    C:\Pai\c++\linked-list\test.cpp(54) : error C2079: 'a' uses undefined
    class 'A<int>'
    C:\Pai\c++\linked-list\test.cpp(56) : error C2228: left of '.disp' must
    have class/struct/union type
    Error executing cl.exe.

    test.obj - 9 error(s), 0 warning(s)

    ***************************************

    How could I write the priviate function which return a structure
    pointer . The error come when I changed the class to a template class.
    How to remove this error.

    Thanks
    Pai
     
    pai, Jun 28, 2006
    #1
    1. Advertising

  2. * pai:
    > #include<iostream.h>


    Non-standard header. Use <iostream>.



    > struct ab{
    > int a;
    > };
    >
    > template <class T>
    > class A{
    >
    > struct ab * ret_1();


    Remove the word 'struct' since it's redundant.


    > public:
    > A();
    > void disp();
    > void ret();
    >
    > };
    >
    > template <class T>
    > void A<T>::ret(){
    >
    > struct ab* b;


    Remove the word 'struct' since it's redundant.


    > b=ret_1();
    >
    > return b;


    Can't return a value from a void function.

    > }




    > template <class T>
    > struct ab * A<T>::ret_1(){


    Remove the word 'struct' since it's parsed as the start of a 'struct'
    declaration (at least by your compiler).


    >
    > struct ab* b;


    Remove the word 'struct' since it's redundant.


    > b=new (struct ab);


    Remove the word 'struct' since it's redundant.


    >
    > return b;
    >
    > }
    >
    > template<class T>
    > A<T>::A(){
    >
    > cout << "A const" ;
    >
    > }
    >
    > template <class T>
    > void A<T>::disp(){
    > cout << "disp" << endl;
    > }
    >
    > int main(){
    > A<int> a;
    > a.disp();
    >
    > return 0;
    > }


    --
    A: Because it messes up the order in which people normally read text.
    Q: Why is it such a bad thing?
    A: Top-posting.
    Q: What is the most annoying thing on usenet and in e-mail?
     
    Alf P. Steinbach, Jun 28, 2006
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris

    Errror finding

    Chris, Jul 1, 2004, in forum: Perl
    Replies:
    3
    Views:
    487
    Gunnar Hjalmarsson
    Jul 1, 2004
  2. Curt_C [MVP]
    Replies:
    4
    Views:
    364
    Curt_C [MVP]
    Jul 19, 2004
  3. Sumaira Ahmad

    Forms Authentication errror

    Sumaira Ahmad, Oct 28, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    449
    =?Utf-8?B?UGF0cmljay5PLklnZQ==?=
    Oct 29, 2004
  4. Guest
    Replies:
    3
    Views:
    1,672
    Guest
    Mar 17, 2005
  5. John Harrison

    Re: open gl/ c++ errror

    John Harrison, Jul 23, 2003, in forum: C++
    Replies:
    0
    Views:
    363
    John Harrison
    Jul 23, 2003
Loading...

Share This Page