Author Topic: Class Inheritance bug?  (Read 1775 times)

Offline Amsterdam

  • Single posting newcomer
  • *
  • Posts: 3
Class Inheritance bug?
« on: September 21, 2016, 04:55:35 pm »
Code::Blocks refuses to recognize class inheritance altogether. Despite the code being simplistic.

Even if I try something banal, such as

class parent {
public:
int forinheritance
};

class child : public parent {
};

Code::Blocks still shows and treats "child" as being memberless.

I just installed Code::Blocks with as part of the standard package, never changed a thing.
Anyone have a clue whats wrong?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11939
    • Travis build status
Re: Class Inheritance bug?
« Reply #1 on: September 21, 2016, 07:30:57 pm »
Please post the exact steps to reproduce the problem?
Where is the cursor when you've hit the control-space to show the auto complete (if the problem is in auto complete, because it is not obvious)?
What version of cb are you using?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Amsterdam

  • Single posting newcomer
  • *
  • Posts: 3
Re: Class Inheritance bug?
« Reply #2 on: September 21, 2016, 07:55:58 pm »
Code::Blocks 16.01 it is.
How can auto complete be the issue? Could you elaborate? The auto complete does indeed recognize classes correctly.

I thought the exact code is redundant, but here it is. Trying to give "Ally" a "cardname" throws an error during compilation: cardname not declared in this scope.


Code: [Select]
#ifndef CARD_H
#define CARD_H

#include <string>

using namespace std;

class Card
{
    public:
        Card();
        virtual ~Card();
                                                               
    protected:
        int cardnumber;
        string cardname;

    private:
};

#endif // CARD_H

#ifndef ALLY_H
#define ALLY_H

#include <string>
#include <vector>

class Ally : public Card
{
    public:
        Ally(int mycardnumber, string mycardname, int mypower, int mystage, string mycategory);
        virtual ~Ally();

    protected:
        int power;
        int stage;
        vector<string> category;

    private:
};

#endif // ALLY_H
« Last Edit: September 22, 2016, 10:29:09 am by Amsterdam »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11939
    • Travis build status
Re: Class Inheritance bug?
« Reply #3 on: September 21, 2016, 10:37:49 pm »
How can auto complete be the issue? Could you elaborate? The auto complete does indeed recognize classes correctly.
Because this is the only thing C::B could be blamed on.
And because this is what I've guessed from your vague post.

I thought the exact code is redundant, but here it is. Trying to give "Ally" a "cardname" throws an error during compilation: cardname not declared in this scope.

Sorry but compilation problems are not related to codeblocks, thus they aren't discussed on the codeblocks forums. Check the rules again if you don't believe me. And codeblocks is not a compiler, but an IDE. There is a serious difference between the two kinds of application types. If you understand the difference there is bigger chance to understand and fix your problem.

p.s. And please next time use code tag to wrap code you're pasting here. They make post a bit more tidy.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Amsterdam

  • Single posting newcomer
  • *
  • Posts: 3
Re: Class Inheritance bug?
« Reply #4 on: September 22, 2016, 10:38:35 am »
So I disabled the auto correct and typed the class names anew, but it did not solve the inheritance problems.

I still do believe the problem to be Codeblocks related, as inheritance worked perfectly fine in other IDEs, utilizing the same code.

p.s. Done.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 11939
    • Travis build status
Re: Class Inheritance bug?
« Reply #5 on: September 22, 2016, 11:51:49 am »
Have you read these:
http://forums.codeblocks.org/index.php/topic,9996.0.html
http://wiki.codeblocks.org/index.php/FAQ-Compiling_(errors)#Q:_How_do_I_troubleshoot_a_compiler_problem.3F
http://wiki.codeblocks.org/index.php/FAQ

And next time you ask for help please post as many details you can.
For example exact steps to reproduce the problem.
It is still not clear what your problem is.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Krice

  • Almost regular
  • **
  • Posts: 125
Re: Class Inheritance bug?
« Reply #6 on: September 23, 2016, 01:19:46 pm »
You need to include card.h in ally.h.

Also, don't put "using namespace std" in headers. You'll thank me later.