446,190 Members | 839 Online
Need help? Post your question and get tips & solutions from a community of 446,190 IT Pros & Developers. It's quick & easy.

# strange template class error

 P: n/a Hi, g++ gives the next error messages test.cpp: In function 'int main()': test.cpp:53: error: invalid conversion from 'int' to 'SmallVectorNoInit (*)()' test.cpp:53: error: initializing argument 1 of 'SmallVector sv(SmallVectorNoInit (*)())' test.cpp:53: error: no match for 'operator=' in 'sv(SmallVectorNoInit (*)())() = 1.0e+0' test.cpp:6: note: candidates are: SmallVector& SmallVector::operator=(const SmallVector&) when it compiles the code below: //////////////////////////////////////////////// struct SmallVectorNoInit {}; template class SmallVector { private: P_numtype data_[N_length]; public: // --- length int length() const { return N_length; } // --- constructors SmallVector() { //meta_Assign //::Assign(data_, P_numtype(), _bz_update()); } SmallVector(const SmallVector& from) { //meta_Assign // ::Assign(data_, from.data_, _bz_update()); } explicit SmallVector(const SmallVectorNoInit&) { } P_numtype& operator ()(int i) { return data_[i]; } const P_numtype& operator ()(int i) const { return data_[i]; } }; int main(void) { SmallVector
4 Replies

 P: n/a Valeriu Catina wrote: g++ gives the next error messages [...] int main(void) { SmallVector sv(2) = 1.; return 0; } //////////////////////////////////////////////// Can anyone figure out what's happening ? Learn to read the error messages. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Oct 3 '06 #2

 P: n/a Valeriu Catina wrote: Hi, g++ gives the next error messages test.cpp: In function 'int main()': test.cpp:53: error: invalid conversion from 'int' to 'SmallVectorNoInit (*)()' test.cpp:53: error: initializing argument 1 of 'SmallVector sv(SmallVectorNoInit (*)())' test.cpp:53: error: no match for 'operator=' in 'sv(SmallVectorNoInit (*)())() = 1.0e+0' test.cpp:6: note: candidates are: SmallVector& SmallVector::operator=(const SmallVector&) when it compiles the code below: //////////////////////////////////////////////// struct SmallVectorNoInit {}; template class SmallVector { private: P_numtype data_[N_length]; public: // --- length int length() const { return N_length; } // --- constructors SmallVector() { //meta_Assign //::Assign(data_, P_numtype(), _bz_update()); } SmallVector(const SmallVector& from) { //meta_Assign // ::Assign(data_, from.data_, _bz_update()); } explicit SmallVector(const SmallVectorNoInit&) { } P_numtype& operator ()(int i) { return data_[i]; } const P_numtype& operator ()(int i) const { return data_[i]; } }; int main(void) { SmallVector sv(2) = 1.; return 0; } //////////////////////////////////////////////// Can anyone figure out what's happening ? The problem is that it thinks you are declaring a function named sv (the rule is that anything that can be a function definition is interpreted that way, and here the parentheses by which you intended to create a temporary instance of SmallVectorNoInit are simply ignored.) Cheers! --M Oct 3 '06 #3

 P: n/a Valeriu Catina wrote: SmallVector sv(2) = 1.; This attempts to call the function passing a int to the parameter which is type SmallVectorNoInit. Oct 3 '06 #4

 P: n/a Victor Bazarov posted: > SmallVector

### This discussion thread is closed

Replies have been disabled for this discussion.