| |

VerySource

 Forgot password?
 Register
Search
View: 946|Reply: 4

A problem with template class inheritance. . . .

[Copy link]

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 Unknown

Post time: 2020-1-31 07:20:01
| Show all posts |Read mode
The following code is reported in GNU G ++
test.cpp: 53: Error: dependency name ‘CAttrValue <TVal> :: CAttrValue’ was resolved to a non-type, but instantiation produced a type
test.cpp: 53: Note: If you want to specify a type, use ‘typename CValue <TVal> :: CValue’
Excuse me, what did I write wrong? ? I use typename CAttrValue <TVal> :: CAttrValue () The result is not executed.

#include <iostream>
#include <ext / hash_map>

using namespace std;
using namespace __gnu_cxx;

typedef unsigned short WORD;

template <typename TVal>
struct CValue
{
        CValue ()
        {
                base = 0;
                extend = 0;
                attach = 0;
                rate = 100;
                value = 0;
        }

        CValue (TVal b, TVal e, TVal a, WORD r)
        {
                base = b;
                extend = e;
                attach = a;
                rate = r;
        }



        TVal base;
        TVal extend;
        TVal attach;
        WORD rate;
        TVal value;
};

template <typename TVal>
struct CMaxValue: CValue <TVal>
{
        CMaxValue ()
        {
                current = 0;
                CValue <TVal> :: CValue <TVal> ();
        }

        CMaxValue (TVal b, TVal e, TVal a, WORD r, TVal c)
        {
                current = c;
                CValue <TVal> :: CValue (b, e, a, r);
        }


        TVal current;

};

int main ()
{

        CMaxValue <long> = CMaxValue <long> (1,2,3,4,5);
        // CMaxValue <long>;
        cout <<. base << endl;
}
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-8 19:00:02
| Show all posts
int main ()
{

        CMaxValue <long> Val = CMaxValue <long> (1,2,3,4,5);
        cout << Val.base << endl;
}
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-3-8 21:45:01
| Show all posts
Brother, how do you get the basic derived class constructor to adjust the syntax of the base class constructor before jumping to deriving from templates?
        CMaxValue (): CValue <TVal> (), current (0)
        {
        }
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-9 13:15:02
| Show all posts
Hehe, learn while using. . . Is the virtual function to be adjusted like me? ?
Reply

Use magic Report

1

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-3-9 20:15:01
| Show all posts
Brother, thank you :)
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list