This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Newb question about "does not name type"

Tags: None
(comma "," separated)
rpmuller@gmail.com
Registered Member
Posts
3
Karma
0
Please help! I'm getting the dreaded "xxx does not name type" error when I'm trying to compile my code.

Here's the deal: I have some code that works just fine. However, I reuse the same 2x2 matrices over and over and over again, and would like to define them once and just reuse them, since all of the reallocation is starting to impact performance.

I'd like to just stick these in a namespace and do something like:


#include <Eigen/Dense>

using namespace Eigen;

namespace Gates
{

Matrix2cd I,H,X,Y,Z;
I << 1,0,0,1;
X << 0,1, 1,0;
Y << 0,cd(0,-1), cd(0,1),0;
Z << 1,0, 0,-1;
H << 1,1, 1,-1;
H /= sqrt(2);
}

However, when I try to do this, I get:

In file included from Dense.cc:3:0:
Gates.h:9:3: error: 'I' does not name a type

I've googled around through earlier postings to the list; most of the time, having the "using namespace Eigen;" line solves the problem, but I have it and I'm still getting the problem.

I'm sure what I'm doing is embarrassingly stupid, but could someone please enlighten me as to what I'm doing wrong?

Thanks,

Rick
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
You cannot put code in a namespace. You should buy or borrow a book on c++.
rpmuller@gmail.com
Registered Member
Posts
3
Karma
0
ggael wrote:You cannot put code in a namespace. You should buy or borrow a book on c++.


Same thing happens, though, if I try to define the matrices as global variables in a module, or if I try to put code in the .h file but out of the namespace:


#include <Eigen/Dense>

using namespace Eigen;

namespace Gates
{

Matrix2cd I,H,X,Y,Z;
}

Gates::I << 1,0,0,1;
rpmuller@gmail.com
Registered Member
Posts
3
Karma
0
ggael wrote:You cannot put code in a namespace. You should buy or borrow a book on c++.


Manged to get it all working using static data. Thanks for your help.


Bookmarks



Who is online

Registered users: Baidu [Spider], Bing [Bot], Google [Bot], rblackwell