Gcc Error Was Not Declared In This Scope
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up “not declared in this scope” error with templates and inheritance [duplicate] up vote 19 down vote favorite 4 This question already has an answer here: accessing protected members of superclass in C++ with templates [duplicate] 2 answers Here is code sample which reproduces my problem: template class Base { public: Base() {} virtual ~Base() {} protected: int myOption; virtual void set() = 0; }; template class ChildClass : public Base < std::vector > { public: ChildClass() {} virtual ~ChildClass() {} protected: virtual void set(); }; template void ChildClass::set() { myOption = 10; } My usage in main(): ChildClass myObject; I get the following error (gcc 4.4.3 on ubuntu): ‘myOption’ was not declared in this scope If my ChildClass would be without new template parameter this would work fine, i.e.: class ChildClass : public Base < std::vector > Edit I've managed to solve it, if my set method looks like: Base >::myOption = 10; It works fine. Still though not sure why I need to specify all template parameters. c++ templates inheritance g++ compiler-errors share|improve this question edited Aug 16 '11 at 9:48 Lightness Races in Orbit 217k36337583 asked Aug 16 '11 at 9:33 Tadzys 4011818 marked as duplicate by BЈовићc++ Users with the c++ badge can single-handedly close c++ questions as duplicates and reopen them as needed. Oct 20 '14 at 15:02 This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. myOption is a dependent name, it will work with this-> –iammilind Aug 16 '11 at 9:48 add
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just http://stackoverflow.com/questions/7076169/not-declared-in-this-scope-error-with-templates-and-inheritance like you, helping each other. Join them; it only takes a minute: Sign up variable was not declared in this scope gcc error up vote 0 down vote favorite I have the following templated function //This is a very naive implementation, but it will do template T determinant(const std::vector> &matrix) { sci::assertThrow(square(matrix), sci::err()); if (matrix.size() == http://stackoverflow.com/questions/36677263/variable-was-not-declared-in-this-scope-gcc-error 1) return matrix[0][0]; else if (matrix.size() == 2) return matrix[0][0] * matrix[1][1] - matrix[0][1] * matrix[1][0]; else { double result = 0; std::vector> minor(matrix.size() - 1); double multiplier = 1.0; for (size_t i = 0; i < matrix.size(); ++i) { for (size_t j = 0; j < minor.size(); ++j) { if (j < i) minor[j] = matrix[j]; else minor[j] = matrix[j + 1]; } result += multiplier * matrix[0][i] * sci::determinant(minor); multiplier *= -1.0; } return result; } } which compiled fine with visual studio 2015, however gcc says g++ -c -Wall -g -std=c++11 -fPIC -o3 -o build/svector.o svector/svector.cpp In file included from svector/svector_internal.h:6:0, from svector/svector.cpp:1: svector/../include/svector/dep/svector.h: In function 'T sci::determinant(const std::vector >&)': svector/../include/svector/dep/svector.h:2888:28: error: 'minor' was not declared in this scope for (size_t j = 0; j < minor.size(); ++j) ^ svector/../include/svector/dep/svector.h:2895:60: error: 'minor' was not declared in this scope result += multiplier * matrix[0][i] * sci::determinant(minor); ^ It looks to me like minor is definitely in scope at the point that gcc is complaining abou
2006, 11:11 PMgreetings, im trying to learn c++ and was working through a tutorial and it wanted me to make a simple "hello world" program. https://ubuntuforums.org/archive/index.php/t-260394.html when i went to compile it gave errors. #include int main() { cout<<"HEY, you, I'm alive! Oh, and Hello World!"; return 0; } and i got these errors: root@error:/home/mark/Programming# g++ helloworld.cpp helloworld.cpp: In function ‘int main()’: helloworld.cpp:5: error: ‘cout’ was not declared in this scope root@error:/home/mark/Programming# gcc helloworld.cpp helloworld.cpp: In function ‘int main()’: helloworld.cpp:5: error: ‘cout’ was not declared in this gcc error scope root@error:/home/mark/Programming# bcc helloworld.cpp ld86: cannot open input file crt0.o i have build-essential installed, also have bcc installed. i cant seem to find any info on such an error, the tutorials didnt speak of it either. what now? i know i cant continue learning c++ if i cant even compile a simple hello world prog. skymtSeptember 18th, 2006, 11:52 PMYou must be gcc error was using an old book. It's "std::cout" now. You'll understand once you get to namespaces. mike3kSeptember 19th, 2006, 04:42 AMalternately, you could just add using std; after the #include. po0fSeptember 19th, 2006, 09:42 AM#include using namespace std; int main() { cout << "Hello world!" << endl; } Or, alternatively: #include using std::cout; using std::endl; int main() { cout << "Hello world!" << endl; } If you're just starting out with C++, I recommend Bruce Eckel's Thinking in C++ series of books. He has generously made them available for free download here (http://mindview.net/Books/TICPP/ThinkingInCPP2e.html). vinay_lakhanpalOctober 28th, 2006, 09:21 PMdid you use gcc to compile the program. Use g++ to compile and it will work Dual CortexOctober 31st, 2006, 05:48 PMdid you use gcc to compile the program. Use g++ to compile and it will work Nah, he just forgot to 'add' the std libary mstationNovember 7th, 2006, 12:15 PMi'll start asking sorry for this but i still don't understand my problem.. im running under ubuntu dapper 6.06.1 and when i try to compile a simple c++ program i get this errors: gcc: prova: Nessun file