type here
Hi, I’m developing a physical simulation in C++ and after some base approach, I’m trying to group my functions in libraries. With functions I didn’t got problems, but now I’m trying to implement a simple library file with a function and my main code didn’t recognize the class.
Those are the errors that I got when I try to compile my main code.
- error: use of undeclared identifier ‘Material’
Material::Material( double initialMass, double initialVolume, double initialAbundance, double initialMassnumber ) { - error: use of undeclared identifier ‘Material’
double Material::getDensity( double New_Nuclei_produced, double Exhausted_Nuclei ) const
If it can help, those are my class library files
#pragma once
#ifndef MATERIAL_H
#define MATERIAL_H
#include "Material.cpp"
class Material
{
private:
double mass ;
double volume ;
double abundance ;
double massnumber ;
public:
Material( double initialMass, double initialVolume, double initialAbundance, double initialMassnumber ) ;
double getDensity(double New_Nuclei_produced, double Exhausted_Nuclei) const;
} ;
#endif
and
#include "NT_functions.h"
#include <iostream>
#include "Material.h"
// This class will evaluate the density of the material in terms of particle per cm3
Material::Material( double initialMass, double initialVolume, double initialAbundance, double initialMassnumber ) {
mass = initialMass ;
volume = initialVolume ;
abundance = initialAbundance ;
massnumber = initialMassnumber ;
} ;
double Material::getDensity( double New_Nuclei_produced, double Exhausted_Nuclei ) const
{
double density ;
// I'm looking for a function that modifies the density for each reaction that occurs
if (New_Nuclei_produced > 1 | Exhausted_Nuclei > 1)
{
density = (Number_of_targets(mass, massnumber, abundance) + New_Nuclei_produced - Exhausted_Nuclei) / volume;
if (density == 0)
{
std::cout << "Exhausted material" << std::endl;
exit(1);
}
}
if (New_Nuclei_produced < 1 && Exhausted_Nuclei < 1)
{
density = Number_of_targets(mass, massnumber, abundance) / volume;
}
return density;
} ;
Can someone please help me understanding what I’m doing wrong?
I tried to rearrange the definition of my class in various ways. The strange thing is that when I was working with my class in a simple file called just Material.cpp without the definition of the class in a file and it’s detail in another, everything worked nice and sound.
Antonio Cicchella is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.