ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
$ make
[ 12%] Building CXX object src/CMakeFiles/lang.dir/IntegerPrimitive.cpp.o
/home/michael/lang/src/IntegerPrimitive.hpp: In member function ‘AbstractObject* Func_print::call(std::vector<AbstractObject*>)’:
/home/michael/lang/src/IntegerPrimitive.hpp:16:9: error: ‘int IntegerPrimitive::value’ is private
/home/michael/lang/src/IntegerPrimitive.cpp:7:87: error: within this context
/home/michael/lang/src/IntegerPrimitive.cpp: In constructor ‘IntegerPrimitive::IntegerPrimitive(std::string&)’:
/home/michael/lang/src/IntegerPrimitive.cpp:14:51: error: no matching function for call to ‘IntegerPrimitive::set(std::string, Func_print*)’
/home/michael/lang/src/Scope.hpp:16:25: note: candidate is: virtual void Scope::set(std::string&, AbstractObject*)
make[2]: *** [src/CMakeFiles/lang.dir/IntegerPrimitive.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/lang.dir/all] Error 2
make: *** [all] Error 2
I can't figure them out, the code looks perfectly fine to me. In case it helps, this is the hierarchy of the classes:
Code:
AbstractObject
Scope
IntegerPrimitive
AbstractFunction
Func_print (in IntegerPrimitive's .cpp file)
If you need the code, I can attach a compressed archive to a later post.
$ make
[ 12%] Building CXX object src/CMakeFiles/lang.dir/IntegerPrimitive.cpp.o
/home/michael/lang/src/IntegerPrimitive.hpp: In member function ‘AbstractObject* Func_print::call(std::vector<AbstractObject*>)’:
/home/michael/lang/src/IntegerPrimitive.hpp:16:9: error: ‘int IntegerPrimitive::value’ is private
/home/michael/lang/src/IntegerPrimitive.cpp:7:87: error: within this context
/home/michael/lang/src/IntegerPrimitive.cpp: In constructor ‘IntegerPrimitive::IntegerPrimitive(std::string&)’:
/home/michael/lang/src/IntegerPrimitive.cpp:14:51: error: no matching function for call to ‘IntegerPrimitive::set(std::string, Func_print*)’
/home/michael/lang/src/Scope.hpp:16:25: note: candidate is: virtual void Scope::set(std::string&, AbstractObject*)
make[2]: *** [src/CMakeFiles/lang.dir/IntegerPrimitive.cpp.o] Error 1
make[1]: *** [src/CMakeFiles/lang.dir/all] Error 2
make: *** [all] Error 2
I can't figure them out, the code looks perfectly fine to me. In case it helps, this is the hierarchy of the classes:
Code:
AbstractObject
Scope
IntegerPrimitive
AbstractFunction
Func_print (in IntegerPrimitive's .cpp file)
If you need the code, I can attach a compressed archive to a later post.
Code:
/home/michael/lang/src/IntegerPrimitive.hpp:16:9: error: ‘int IntegerPrimitive::value’ is private
/home/michael/lang/src/IntegerPrimitive.cpp:7:87: error: within this context
- looks like you are trying to use a private member directly rather than trough a public method belonging to the same class.
#ifndef __IntegerPrimitive_hpp_INCLUDE_GUARD__
#define __IntegerPrimitive_hpp_INCLUDE_GUARD__
#include "Scope.hpp"
#include "AbstractFunction.hpp"
#include <cstdlib>
#include <string>
#include <cstdio>
class IntegerPrimitive : public Scope
{
public:
IntegerPrimitive(std::string &str);
private:
int value; // this is the error you pointed out
};
#endif // #ifndef __IntegerPrimitive_hpp_INCLUDE_GUARD__
What's wrong with defining a private variable, how's that an error?
What's wrong with defining a private variable, how's that an error?
Defining a private variable is not the problem, accessing it "directly" IS. You need to read up on the use of making a variable 'private'. Private variables can be accessed only by the members of the class in question, nothing else.
/home/michael/lang/src/IntegerPrimitive.cpp: In constructor ‘IntegerPrimitive::IntegerPrimitive(std::string&)’:
/home/michael/lang/src/IntegerPrimitive.cpp:14:51: error: no matching function for call to ‘IntegerPrimitive::set(std::string, Func_print*)’
/home/michael/lang/src/Scope.hpp:16:25: note: candidate is: virtual void Scope::set(std::string&, AbstractObject*)
/home/michael/lang/src/IntegerPrimitive.cpp: In constructor ‘IntegerPrimitive::IntegerPrimitive(std::string&)’:
/home/michael/lang/src/IntegerPrimitive.cpp:14:51: error: no matching function for call to ‘IntegerPrimitive::set(std::string, Func_print*)’
/home/michael/lang/src/Scope.hpp:16:25: note: candidate is: virtual void Scope::set(std::string&, AbstractObject*)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.