| |

VerySource

 Forgot password?
 Register
Search
Author: 661193

Class template issue ver2

[Copy link]

3

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-7-11 10:45:01
| Show all posts
You may not have created an object

such as

         One<10,20> o1;
fun2(o1);
cout<<o1<<endl;

Two<int> ti1;
cout<<ti1<<endl;
fun1(ti1);
Reply

Use magic Report

3

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-7-16 09:45:01
| Show all posts
Although my question may not have any practical value, if this question is not understood

I really can't learn anymore, there is always a pimple in my heart

I hope that a master who sees through C++ will come to pull the rookie!
Reply

Use magic Report

0

Threads

2

Posts

3.00

Credits

Newbie

Rank: 1

Credits
3.00

 China

Post time: 2020-7-18 07:45:01
| Show all posts
The most direct way is to throw the declaration and definition of the non-binding friend template function in the class body
Reply

Use magic Report

3

Threads

10

Posts

10.00

Credits

Newbie

Rank: 1

Credits
10.00

 China

 Author| Post time: 2020-7-21 09:15:01
| Show all posts
New discovery in vs

Two's output overload function can be compiled

It seems this question is really dark, ha ha
Reply

Use magic Report

0

Threads

55

Posts

44.00

Credits

Newbie

Rank: 1

Credits
44.00

 Invalid IP Address

Post time: 2020-7-23 17:30:01
| Show all posts
template<int i1,int i2>
class One
{
template<int ii1,int ii2> friend ostream&operator<<(ostream&,const One<ii1,ii2>&);
template<int ii1,int ii2> friend void fun2(const One<ii1,ii2>&);
};

template<int ii1,int ii2> ostream&operator<<(ostream&x,const One<ii1,ii2>&){return x;}
template<int ii1,int ii2> void fun2(const One<ii1,ii2>&){}

template<class T>
class Two
{
template<class TT> friend ostream&operator<<(ostream&,const Two<TT>&);
template<class TT> friend void fun1(const Two<TT>&);

};

template<class TT> ostream&operator<<(ostream&x,const Two<TT>&){return x;}
template<class TT> void fun1(const Two<TT>&){}
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