Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: expected identifier before numeric constant

Tags:

c++

matrix

I'm trying to write a small program using MTL, but I'm getting the mentioned error when I try to make a MTL Matrix a member of a class.

#include <boost/numeric/mtl/mtl.hpp>

class myClass
{
private:
    mtl::dense2D<double> Ke(6,6);
};

However, there is no problem with the same statement in main():

#include <boost/numeric/mtl/mtl.hpp>

int main(int argc, char** argv)
{
    mtl::dense2D<double> Ke(6,6);
    return 0;    
}

I'm very new to C++, and I don't think this is really related to the MTL, but that's where the error occurred for me.

like image 828
Psirus Avatar asked Dec 12 '22 13:12

Psirus


1 Answers

You need to do that in the constructor's initialiser list.

class myClass {
    mtl::dense2D<double> Ke;
public:
    myClass() : Ke(mtl::dense2D<double>(6, 6)) { }
};
like image 126
Cat Plus Plus Avatar answered Dec 28 '22 13:12

Cat Plus Plus