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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:31:00+00:00 2026-05-24T03:31:00+00:00

I am having a bit of trouble with C++ classes. I am writing a

  • 0

I am having a bit of trouble with C++ classes. I am writing a class (cSpline) to do a cubic spline fit on a set of input points. I want to use a cSpline object within another class (ss304, which provides properties of type 304 stainless steel as a function of temperature). I have four files. Here is the code I have come up with:

cSpline.h:

class cSpline {
private:
  double *setCoeffs(double* x_in, double* f_in, int size);
  double *coeffs;
  double *f;
  double *x;
  int sizex;
public:
  double *interpolate(double* y, int sizey);
  cSpline(double* x_in, double* f_in, int size);
};

cSpline.cpp:

cSpline::cSpline(double* x_in, double* f_in, int size) {
  f = f_in;
  x = x_in;
  sizex = size;
  coeffs = setCoeffs(x, f, size);
}

double* cSpline::setCoeffs (double* x_in, double* f_in, int size) {
  double *ypp = new double[size];
  for (int i = 0; i < size; i++) {
    ypp[i] = 0.0;
  }
  return ypp;
}

double* cSpline::interpolate(double* y, int sizey){
  double *g = new double[sizey];
  for (int i = 0; i < sizey; i++) {
    g[i] = 0.0;
  }
  return g;
}

ss304.h:

#include "cSpline.h"

class SS304 {
private:
    // Material constants
  static const double T0 =     273.0; // standard temp, K
  static const double rho0 =  7924.0; // density at STP, kg/m^3
  static const double Tm =    1700.0; // melting temp, K
  static const double Hm =  265.3+03; // heat of melting, J/kg
  static const double rhom =  7015.0; // density of molten phase at Tm (iron), kg/m^3/K
  static const double drdt =  -0.883; // temperature coefficient of densiy at Tm, kg/m^3/K
  static const double Tv =    3100.0; // vaporization temperature, K
  static const double Hv = 6.258e+06; // heat of vaporization, J/kg
    // Property Array Sizes
  static const int Na1 = 10;
    // Property Arrays
  double alpha1[Na1];   //thermal expansivity, T0 < T < Tm, 1/K
  double Talpha1[Na1];
  cSpline csalpha1(double* x, double* f, int size);
public:
  double* alpha;
  void setProp1D(double* T, int size);
  SS304();
};

ss304.cpp:

#include "ss304.h"

SS304::SS304() {
  double alpha1[Na1]  = {13.6e-6, 16.1e-6, 17.15e-6, 17.8e-6, 18.65e-6, 19.2e-06, 19.85e-06, 20.55e-06, 20.9e-06};
  double Talpha1[Na1] = {   200.,    400.,     500.,    600.,     700.,     800.,     1000.,     1200.,    1400.};

  cSpline csalpha1(Talpha1, alpha1, Na1);
}

void SS304::setProp1D(double* T, int size) {
  double* alpha = new double[size];
  alpha[0] = csalpha1.interpolate(T[0]);
}

What I am trying to accomplish here is this: Upon creation of a ss304 object, I set the properties of 304 stainless, in this case alpha1, at a given set of temperatures, Talpha1. Then I create a cSpline object, csalpha1, for later use. Creation of the cSpline object goes ahead and calculates the spline coefficients. Then, when I call SS304::setProp1D with an array of temperatures, it should set the values of alpha[] based on an interpolation of the cubic spline at each temperature in T[]. Obviously, I left out the full implementation of the spline for the sake of space, but the implementation is irrelevant to the error I get, which is:

ss304.cpp: In member function ‘void SS304::setProp1D(double*, int)’:

ss304.cpp:12: error: ‘((SS304*)this)->SS304::csalpha1’ does not have class type

So, I think I have some basic misunderstanding of how exactly classes work in C++. I think I am trying to use them as I do in Python, where I have this working just fine. But, obviously I am missing something in C++. I have googled around quite a bit, but not found any help that I understood. Any help would be greatly 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-05-24T03:31:00+00:00Added an answer on May 24, 2026 at 3:31 am

    You can’t initialize a data member in the constructor by calling the data member’s constructor. You will need an assignment or initialization method for the object:

    SS304::SS304()
    {
        static const double alpha1[Na1]  = {13.6e-6, 16.1e-6, 17.15e-6,
                                            17.8e-6, 18.65e-6, 19.2e-06,
                                            19.85e-06, 20.55e-06, 20.9e-06};
        static const double Talpha1[Na1] = {200.,    400.,     500.,
                                            600.,    700.,     800.,
                                           1000.,   1200.,    1400.};
        csalpha1.initialize(Talpha1, alpha1, Na1);
    } 
    

    Also, familiarize yourself with initialization lists and the C++ FAQ (which can be found by searching the web).

    I converted the arrays into static const to force the compiler to place the data into Read-Only Memory and to access it from the Read-Only Memory (versus copying the data onto the stack).

    The compiler will use a default or empty constructor when creating data members of a class.

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

Sidebar

Related Questions

I'm having some trouble understanding a bit of code. I've got 2 classes Company
Having a bit of trouble with the syntax where we want to call a
Im having some trouble understanding Inheritance in classes and wondering why this bit of
I'm having a bit of trouble using variable generated php div classes and jQuery
I seem to be having a bit of trouble with using classes from other
Im having a bit of trouble with ie7(who hasnt) I want the slide thats
I'm having a bit of trouble serializing a form <form> <input type=text name=name1 value=value1/>
im having a bit of trouble writing a keyboard hook in C++. I can
How to use the database mapper with the paginator? I'm having a bit trouble
Having a bit of trouble using the List.Find with a custom predicate i have

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.