Jump to content
  • Advertisement
Sign in to follow this  
Zipster

A vector class

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

As always, seeing your code would be helpful [smile]

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.

Share this post


Link to post
Share on other sites
Actually I am a complete idiot. In my derived vector class I always had constructors that called the default constructor of the base data class, which contained the operator class. I just had to add a constructor in the vector class that called the non-default constructor in the base class, and it worked. I suppose I got caught up in all the expression template code that I overlooked just what the error was telling me.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!