Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I tried to overload Below is my code main W460239957@DESKTOP-Q068R3R:/mnt/h/3010/Hw2$ g++ -std=c++17 Counter.hpp main.cpp Counter.hpp:13:72: warning: friend declaration 'std::ostream& operator&)' declares a non-template function [-Wnon-template-friend]

I tried to overload

image text in transcribed

Below is my code

image text in transcribed

main

image text in transcribed

W460239957@DESKTOP-Q068R3R:/mnt/h/3010/Hw2$ g++ -std=c++17 Counter.hpp main.cpp Counter.hpp:13:72: warning: friend declaration 'std::ostream& operator&)' declares a non-template function [-Wnon-template-friend] 13 friend std::ostream& operator &b); Counter.hpp:13:72: note: (if this is not what you intended, make sure the function template has already been declared and add after the function name here) /usr/bin/ld: /tmp/ccVvVwry.o: in function 'main': main.cpp:(. text+ex204): undefined reference to operator, std::allocator > > const&)' collect2: error: ld returned 1 exit status 6 7 8 9 10 template class Counter { public: Counter(); Counter(std::vector vals); I getList(); friend std::ostream& operator &b); 11 12 13 14 15 16 17 private: std::map list; }; 18 19 20 21 22 23 24 template std::ostream& operator &b) std::map list = b.getlist(); typename std::map::iterator it; for (it list.begin(); it != list.end(); it++) { os it->first it->second; } return os; ] 25 26 27 28 29 30 31 32 33 34 template I Counter::getList(){ return list; } 35 36 37 38 39 40 41 template Counter::Counter(){ //Do nothing; } 42 43 44 45 46 template Counter::Counter(std::vector vals) { for (int i = 0; i #include 3 4 5 6 int main() { Counter int> p1; std::vector<:string> p2 = {"cat", "hourse", "king", "zhengyuan"}; Counter<:string> p3(p2); std::cout

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Database Relational Model A Retrospective Review And Analysis

Authors: C. J. Date

1st Edition

0201612941, 978-0201612943

More Books

Students also viewed these Databases questions

Question

3. What changes should I be making?

Answered: 1 week ago

Question

2. Why?

Answered: 1 week ago