Topic: Is this compiler error a bug in Visual C++ or a feature of STL?
Author: Al Stevens <alstevens@midifitz.com>
Date: 1999/04/18 Raw View
The program compiles without errors with mingw32 egcs 2.91.60.
However, your dummy string declaration needs a semicolon. Make sure the rest
of your code is what you are having trouble with.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: jeremy_jameson@my-dejanews.com
Date: 1999/04/16 Raw View
I encountered a problem while building a test stub for a matrix class that I
am working on. When I compile the code below with Visual C++ 5.0 (SP3), I get
the following compile time error (don't you just love these STL errors?) :
C:\DevTools\DevStudio\VC\INCLUDE\vector(36) : error C2440: 'default
argument' : cannot convert from 'class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char>
>' to 'const class std::allocator<char> &'
Reason: cannot convert from 'class std::basic_string<char,struct
std::char_traits<char>,class std::allocator<char> >' to 'const class
std::allocator<char>'
No user-defined-conversion operator available that can perform this
conversion, or the operator cannot be called
However, if I create a dummy string variable the error goes away. I would
certainly not categorize myself as an template expert (in fact I usually
cringe when I look at some of the STL documentation) so this could just be a
feature of the STL. Unfortunately, I don't have any other compilers to try
this out on. What do the C++ experts say?
Regards,
Jeremy Jameson
Micromedex, Inc.
//-------------------------------------------------------------------------
#include <vector>
#include <string>
template <class T>
class matrix
{
private:
typedef std::vector<T> matrix_type;
public:
typedef matrix_type::value_type value_type;
typedef matrix_type::reference reference;
typedef matrix_type::const_reference const_reference;
typedef matrix_type::size_type size_type;
private:
size_type m_nRows, m_nColumns;
matrix_type m_Matrix;
public:
matrix( size_type rows, size_type columns ) :
m_nRows( rows ), m_nColumns( columns ),
m_Matrix( rows * columns )
{
}
size_type rows( ) const { return m_nRows; }
size_type columns( ) const { return m_nColumns; }
reference operator( ) ( size_type row, size_type column )
{
return m_Matrix[row * m_nColumns + column];
}
const_reference operator( ) ( size_type row, size_type column ) const
{
return m_Matrix[row * m_nColumns + column];
}
};
int main( )
{
// Uncomment the following line to workaround the C2440 compile error.
//std::string Work_Around_for_C2440_Compile_Error
matrix<std::string> Matrix( 2, 2 );
Matrix( 0, 0 ) = "(0,0)";
Matrix( 0, 1 ) = "(0,1)";
Matrix( 1, 0 ) = "(1,0)";
Matrix( 1, 1 ) = "(1,1)";
return( 0 );
}
-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]