LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 01-16-2011, 11:08 AM   #1
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
C++ errors


When compiling my project I get these errors:

Code:
$ 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.
 
Old 01-16-2011, 11:41 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
When compiling my project I get these errors:

Code:
$ 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.
 
2 members found this post helpful.
Old 01-16-2011, 11:50 AM   #3
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Code:
#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?
 
Old 01-16-2011, 12:11 PM   #4
TheIndependentAquarius
Senior Member
 
Registered: Dec 2008
Posts: 4,622
Blog Entries: 29

Rep: Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896Reputation: 896
Quote:
Originally Posted by MTK358 View Post
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.
 
1 members found this post helpful.
Old 01-16-2011, 12:37 PM   #5
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
OK, I fixed it.

Now what about this:

Code:
/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*)
 
Old 01-16-2011, 01:13 PM   #6
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
OK, I fixed it.

Now what about this:

Code:
/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*)
See the item in red - as before.
 
Old 01-16-2011, 01:30 PM   #7
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
IntegerPrimitive is a subclass of Scope and Func_print is a subclass of AbstractObject.

And set() is public.
 
Old 01-16-2011, 01:42 PM   #8
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
IntegerPrimitive is a subclass of Scope and Func_print is a subclass of AbstractObject.

And set() is public.
Does the function signature (of 'IntegerPrimitive::set') match ? The compiler says it doesn't.

Last edited by Sergei Steshenko; 01-16-2011 at 01:43 PM.
 
Old 01-16-2011, 01:45 PM   #9
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
There is no IntegerPrimitive::set().
 
Old 01-16-2011, 01:49 PM   #10
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
There is no IntegerPrimitive::set().
Then, what is the question ? I.e. how can the compiler use a function which doesn't exist ?
 
Old 01-16-2011, 01:51 PM   #11
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
IntegerPrimitive is derived from Scope, which has the set() function.
 
Old 01-16-2011, 01:55 PM   #12
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
IntegerPrimitive is derived from Scope, which has the set() function.
Again, does the signature match ?
 
Old 01-16-2011, 01:58 PM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Original Poster
Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Here is the signature:

Code:
virtual void set(std::string &name, AbstractObject *value);
Here is the call that causes the error:

Code:
set(std::string("print"), new Func_print(this));
 
Old 01-16-2011, 02:03 PM   #14
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by MTK358 View Post
Here is the signature:

Code:
virtual void set(std::string &name, AbstractObject *value);
Here is the call that causes the error:

Code:
set(std::string("print"), new Func_print(this));
So, did you implement the function marked virtual in the derived class ?
 
Old 01-16-2011, 02:29 PM   #15
johnsfine
Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,095

Rep: Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112Reputation: 1112
Quote:
Originally Posted by MTK358 View Post
this is the hierarchy of the classes:

Code:
AbstractObject
    Scope
        IntegerPrimitive
    AbstractFunction
        Func_print (in IntegerPrimitive's .cpp file)
Is AbstractFunction a public base class of Func_print?
Is AbstractObject a public base class of AbstractFunction?

Code:
no matching function for call to ‘IntegerPrimitive::set(std::string, Func_print*)
What declarations of set() are in IntegerPrimitive? Any chance such declaration hides the base class declaration of set() that you want?

Quote:
Originally Posted by Sergei Steshenko View Post
So, did you implement the function marked virtual in the derived class ?
Missing that would give a different error message (if it were an error at all).

Last edited by johnsfine; 01-16-2011 at 02:30 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
repeatable disk read/write errors with no errors logged by kernel or SMART mxl2 Linux - Hardware 9 04-02-2011 09:27 AM
yum update transaction check errors & mirror errors tonycunn Linux - Software 2 11-29-2010 08:16 AM
Errors, Errors, and more Errors (KDE 3.4.x GUI Errors) Dralnu Linux - Software 2 05-13-2006 08:30 AM
Errors during filesystem check with one kernel while no errors with other kernel Potentials Linux - General 11 12-30-2003 04:24 AM
QMAIL errors errors.. YourForum Linux - Software 0 11-27-2003 12:30 PM


All times are GMT -5. The time now is 09:58 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration