Skip to main content
Added note about variable naming
Source Link
Peter Bloomfield
  • 11k
  • 9
  • 48
  • 87

You need to include roundto() in your class declaration, e.g. something like this:

class cSpeedOfSound {
public:
    cSpeedOfSound(float *i,float *C);

private:
    float roundto(float x, float dp);

    float *C;
    float *a;
    float *i;
};

In C++, class structures are fixed. You can define the body of a function almost anywhere, but all member functions/data must be specified in the original declaration.


As a side note, it's worth pointing out that you have a naming conflict in your code. You have member variables called i and C, and you have totally separate function parameters called i and C. The compiler won't complain about this (the function parameters will simply mask the member variables), but it may not do what you expect.

You need to include roundto() in your class declaration, e.g. something like this:

class cSpeedOfSound {
public:
    cSpeedOfSound(float *i,float *C);

private:
    float roundto(float x, float dp);

    float *C;
    float *a;
    float *i;
};

In C++, class structures are fixed. You can define the body of a function almost anywhere, but all member functions/data must be specified in the original declaration.

You need to include roundto() in your class declaration, e.g. something like this:

class cSpeedOfSound {
public:
    cSpeedOfSound(float *i,float *C);

private:
    float roundto(float x, float dp);

    float *C;
    float *a;
    float *i;
};

In C++, class structures are fixed. You can define the body of a function almost anywhere, but all member functions/data must be specified in the original declaration.


As a side note, it's worth pointing out that you have a naming conflict in your code. You have member variables called i and C, and you have totally separate function parameters called i and C. The compiler won't complain about this (the function parameters will simply mask the member variables), but it may not do what you expect.

Source Link
Peter Bloomfield
  • 11k
  • 9
  • 48
  • 87

You need to include roundto() in your class declaration, e.g. something like this:

class cSpeedOfSound {
public:
    cSpeedOfSound(float *i,float *C);

private:
    float roundto(float x, float dp);

    float *C;
    float *a;
    float *i;
};

In C++, class structures are fixed. You can define the body of a function almost anywhere, but all member functions/data must be specified in the original declaration.