Q:

Which, if any, of the following static data member declarations and definitions are errors? Explain why

0

Which, if any, of the following static data member declarations and definitions are errors? Explain why.

// example.h
class Example {
public:
 static double rate = 6.5; static const int vecSize = 20; static vector<double> vec(vecSize);
};
// example.C
#include "example.h"
double Example::rate;
vector<double> Example::vec;

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

    // example.h
    class Example {
    public:
      static double rate; // = 6.5;
      // static member should be initialize ouside class
      static const int vecSize = 20;
      static vector<double> vec; //(vecSize);
      // 1. cannot use parentheses as in-class initializer
      // 2. static member should be initialize ouside class
    };

    // example.C
    #include "example.h"
    double Example::rate = 6.5;
    // should initialize static data member
    vector<double> Example::vec(vecSize);
    // should initialize static data member

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now