• 10
• 9
• 10
• 9
• 10

# A vector class

This topic is 4495 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm currently experimenting with a few different vector implementations and at the moment am working on one similar to the array class developed in this article. It has all the features I want except for explicit member referencing (i.e. v.X, v.Y) for the common 2D, 3D, and 4D vector types, however I was able to implement that. What's really bugging me is an annoying compiler error C2512, which is 'no appropriate default constructor available'. I know why it's happening, but I have no idea how to get around it. If you take a look at the article I linked, the array class keeps a member variable that when evaluated either returns values from a vector or evaluates a subexpression, which is in turn an array type and does the same thing until all evaluation paths end at vectors. However the operator class array_addition has no default constructor since the references need to be initialized. Unless I'm missing something, it seems as though the code in the article would suffer from the same problem however the author doesn't mention it anywhere and instead says everything compiles fine. My code isn't exactly the same as his but the expression templates follow the same design and the few changes I made don't affect this part of the code. To be honest I've never really encountered the case where you have a nested class without a default constructor, so I don't know if that's a semantic error or there are ways to invoke a non-default constructor from the containing class. The error points to the constructor of the containing class, if that helps. If you need to see any code just let me know, but it's pretty much along the same lines as the article's.

##### Share on other sites
The question you really should be asking yourself is "why does my array_addition (or vector_addition, whatever your equivalent is) need to be default constructed?". The answer is, it shouldn't (which is why the code in the article will compile fine), yet for some reason your code is requiring it.

Quote:
 or there are ways to invoke a non-default constructor from the containing class.

You mean something like this?

struct A{    A(int val) : val(val) {}    int val;};struct B{    B(int val) : a(val) {}    A a;};

If that is what you're after, I'm curious as to why your array_addition equivalent is a member of another class. While I've only dabbled a little in expression templates, it doesn't seem like there would be any use for this.