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 7506263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:12:26+00:00 2026-05-29T22:12:26+00:00

I am from Java backgroung and new to C++. There is a template which

  • 0

I am from Java backgroung and new to C++.
There is a template which i have made.

template <class T>
class Shape {
int val,val_new;

public:

Shape(T initval)
{
val=initval;
}

T get()
{
return val;
}

void set (T newval)
{
val_new = newval;
}
void copy()
{
this.val= val_new;
}
};

There is a class Rectangle to use this template

#include <iostream>
#include<math.h>
using namespace std;
class Rectangle
{
private:
Shape<TwoPoint> val;
TwoPoint newval;
public:
Rectangle(TwoPoint i)
{
     val = new Shape<TwoPoint> (i);
}
Shape<TwoPoint> read()
{
     return val;
}

void load(TwoPoint newval)
{
     load_called=1;
     this.newval=newval;
}
void increment()
{
   val=val+1;
}

void decrement()
{
   val= val-1;
}
void actions()
{ 
 if (load_called)
value.set(new TwoPoint(newval));
}
};

TwoPoint is a class used for generics.

class TwoPoint
{
  int width;
  int value;
  public:
  TwoPoint(int v, int w)
  {
   value=v;
   width=w;
   }
   TwoPoint(TwoPoint t)
   {
    value= t.value;
    width= t.width;
   }
   int getWidth()
   {
     return width;
   }
    int getValue()
    {
       return value;
    }};

But i am getting a lot of errors like constructor mismatches, conversion failures. Can somebody please help me.

There are errors like

 In constructor `Rectangle::Rectangle<TwoPoint>':
 error: no matching function for call to Shape<TwoPoint>:: Shape()'
 note: candidates are: Shape<T>::Shape<T> with [T = TwoPoint]

Two similar errors are there

  • 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-05-29T22:12:28+00:00Added an answer on May 29, 2026 at 10:12 pm

    First; in the following piece of code, this is indexed with ‘.’, but this is a pointer so you should use val = val_new; (implicitly this->val = val_new;):

    void copy() {
      this.val = val_new;
    }
    

    … should be…

    void copy() {
      val = val_new;
      // or this->val = val_new;
    }
    

    Same problem at Rectangle::load.

    Secondly: like others are saying, you should use T val, val_new instead of int val, val_new.

    And last but not least:

    Rectangle(TwoPoint i) {
         val = new Shape<TwoPoint> (i);
    }
    

    val should be initalized like this:

    Rectangle(TwoPoint i)
        : val(Shape<TwoPoint> (i)) { }
    

    There are two reasons for this:

    1. If val is not initalized like this, the default constructor (Shape<T>::Shape()) is used, which does not exist.
    2. The new keyword allocates new memory in C++ and returns a pointer. It should be left away since val is not a pointer but a value.

    At constructors you can intialize member values by calling their constructors, or calling them with their value (auto-generated copy constructor). This should be prefixed with a colon an followed by the function body.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wanted to run a .cmd file from Java. I have something which works
I'm new to Windows Forms from the Java Swing world. Is there any equivalent
I have a problem. I'm using a FileObserver , which moves new files from
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering
I come from Java Background and so used to Debugging using Eclipse but have
Static variable gotcha in php I am from Java background and have switched to
how can I change the background of an ImageView from java? I have an
In Java I have a hobby with thread, for example: Thread thread = new
I come from a .NET background and am completely new to Java and am
Disclaimer, I'm from a Java background. I don't do much C#. There's a great

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.