Category : accessor

class A{ char info[256]; public: char* getInfo(); A(char i[256]); //A.cpp #include "A.h" char * A::getInfo(){ return(&info[256]); } A::A(char i[256]){ info[256]=i[256]; } I’m struggling with the accessor. When I try to use getInfo(), I get a char*, and thus with char test[256] = "test"; FractionException d(test); for (int i = 0; i < 256; i++) { ..

Read more

In c++ we have accessor methods such as int get_value() const;. If we try to change the state of object inside this method the compiler will throw an error. Has java such an alternative keyword to make sure that the state of object does not change? Source: Windows Que..

Read more

I recently created two classes in my c++ project, one is Player class and the other Vector class (not the array). Player.h #ifndef Player_h #define Player_h #include <iostream> #include <string> #include <cmath> /* Player */ class Player{ public: /* Constructor */ Player(std::string name = "name", double x = 0, double y = 0, double z ..

Read more

//inside the class NutritionData, declaration double getCaloriesPerServing() const; //Outside the class Nutrition Data, definition double NutritionData::getCaloriesPerServing() const { calPerServing = calFromCarb+calFromFat+calFromProtein; return calPerServing; } Error: says the expression calPerServing must be a modifiable lvalue. Instructor directions: 1.Add a const member function named getCaloriesPerServing that returns the total calories from carb, protein and fat. Again, don’t ..

Read more