The code shown below in the description runs here when I try it, but when I wrote it on code blocks it gave me 5 errors.. 1. expected imitializer before '<' token. (line 19). 2. reference to 'pair' is ambiguous. (line 26). 3. expected primary-expression before double. (line 26). 4. expected ';' before 'double'. (line 26). 5. 'obj' was not declared in this scope. (line 27). Any help please? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

The code shown below in the description runs here when I try it, but when I wrote it on code blocks it gave me 5 errors.. 1. expected imitializer before '<' token. (line 19). 2. reference to 'pair' is ambiguous. (line 26). 3. expected primary-expression before double. (line 26). 4. expected ';' before 'double'. (line 26). 5. 'obj' was not declared in this scope. (line 27). Any help please?

#include <iostream> using namespace std; template <class T> class Pair { private: T first, second; public: Pair (T a, T b): first(a), second(b) { } T bigger(); }; template <class T> T Pair<T>::bigger() { return (first>second ? first : second); } int main() { Pair <double> obj(23.43, 5.68); cout << obj.bigger(); return 0; }

9th Jul 2016, 3:46 PM
Khaled Gamal Saad
Khaled Gamal Saad - avatar
5 Answers
+ 2
Go to Toolbar -> Settings -> Compiler In the "Selected compiler" drop-down menu, make sure "GNU GCC Compiler" is selected Below that, select the "compiler settings" tab and then the "compiler flags" tab underneath In the list below, make sure the box for "Have g++ follow the C++11 ISO C++ language standard [-std=c++11]" is checked Click OK to save from stack overflow
10th Jul 2016, 6:28 PM
mazen aljeddani
+ 1
did you activated the new c++11 language features, -std=c++11
10th Jul 2016, 6:23 PM
mazen aljeddani
+ 1
you are welcome :)
10th Jul 2016, 6:39 PM
mazen aljeddani
0
no I did not, how do I do this?
10th Jul 2016, 6:25 PM
Khaled Gamal Saad
Khaled Gamal Saad - avatar
0
thank you so much Mr Mazen ☺
10th Jul 2016, 6:37 PM
Khaled Gamal Saad
Khaled Gamal Saad - avatar