Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9128547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:32:26+00:00 2026-06-17T07:32:26+00:00

I was on codepad and I was trying to build up my skills using

  • 0

I was on codepad and I was trying to build up my skills using C++. I’d never used templates much before, so I tried looking into how to use them. The code below is the result, and unfortunately, it does not work. I did try to search for solutions to my problem, but since I don’t have much experience using templates, I couldn’t make any connections between my problem and other problems. So, I decided to ask for help.

template <class A>
class Vector2 {
public:
    A x,y;
    Vector2(A xp, A yp){
        this->x = xp;
        this->y = yp;
    }
};

template <class B, class A>
class rayToCast {
public:
    rayToCast(B angle, Vector2<A> origin, Vector2<A> point1, Vector2<A> point2){
        this->RAngle = angle;
        this->Point1 = point1;
        this->Point2 = point2;
    }
private:
    B RAngle;
    Vector2<A> point1,point2;
};

int main(){
    rayToCast<short int, float> ray(45, Vector2<float>(0.0, 0.0), Vector2<float>(-10.0, -3.0), Vector2<float>(5.0, 7.0));
    return 0;
}

Here’s the output:

t.cpp: In constructor 'rayToCast<B, A>::rayToCast(B, Vector2<A>, Vector2<A>, Vector2<A>) [with B = short int, A = float]':
t.cpp:26:   instantiated from here
Line 14: error: no matching function for call to 'Vector2<float>::Vector2()'
compilation terminated due to -Wfatal-errors.

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T07:32:27+00:00Added an answer on June 17, 2026 at 7:32 am

    The rayToCast constructor tries to initialize point1 and point2 by calling Vector2‘s default constructor. But it doesn’t have one.

    You either have to provide a default constructor for the vector class, or explicitly initialize the members of rayToCast. One way is to do like this:

    rayToCast(B angle, Vector2<A> origin, Vector2<A> point1, Vector2<A> point2)
       : RAngle(angle), point1(point1), point2(point2)
    { }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am trying escape some data before it goes into my database, but i
I'm trying to pack some unsigned int data into a string buffer created using
In localhost (using Wamp on windows). I'm trying to use this: <? $xml =
I used to use: http://codepad.viper-7.com However it seems like it's down atm. Are there
Sometimes I see people use http://codepad.org as a way to quickly run/test their Perl
I put the following into Ideone.com (and codepad.org): #include <iostream> #include <string> #include <tr1/functional>
http://codepad.viper-7.com/ezvlkQ So, I'm trying to figure out: ...?php $object = new A(); class A
I kinda like codepad online editor (supports C++) , but I'd like to use
Compiling this on Codepad : #include <iostream> using namespace std; void main (void) {
I tried the following code on both codepad.org and ideone.com : char* ptr =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.