2

Here is the EXACT Error given by Code::Blocks

D:\cpp\AdventureTimeTest\main.cpp|12|error: 'class adventure' has no member named 'drawMap'

Here is my code:-

In main.cpp

#include <iostream>
#include "adventure.h"

using namespace std;

int main()
{
    adventure a;

    a.setMapSize(10);
    a.drawMap();

    return 0;
}

In adventure.h

class adventure
{
    public:
        adventure();
        virtual ~adventure();

        int mapSize;
        void setMapSize(int mapSize);
        int getMapSize();

        void drawMap();

    protected:
    private:
};

and, finally, in adventure.cpp

#include <iostream>
#include "adventure.h"

using namespace std;

adventure::adventure()
{
}

adventure::~adventure()
{
}

void adventure::setMapSize(int par1)
{
    mapSize = par1;
}

int adventure::getMapSize()
{
    return mapSize;
}

void adventure::drawMap()
{
    for(int x = 0; x <= mapSize; x++)
    {
        for(int y = 0; y <= mapSize; y++)
        {
            cout << ". ";
        }
        cout << endl;
    }
}

Thanks, hopefully I can get this issue resolved fairly quickly.

Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
Rijnhardt
  • 2,344
  • 5
  • 19
  • 27
  • Is this where you need one of those virtual things??? – Jiminion Aug 26 '13 at 13:53
  • 5
    Is this your exact, copy pasted code, Rijnhardt? – jrok Aug 26 '13 at 13:54
  • @jrok Yes sir. It is a carbon copy of the source code. – Rijnhardt Aug 26 '13 at 13:55
  • 8
    Clean everything and rebuild all. – Daniel Daranas Aug 26 '13 at 13:56
  • @DanielDaranas I am trying to build it, it will not allow me to do just that. – Rijnhardt Aug 26 '13 at 13:57
  • Ctrl+F11, rebuild everything. The code looks fine. – jrok Aug 26 '13 at 13:57
  • 2
    @Rijnhardt, is there a possibility that some other part of your code abuses the preprocessor? For instance, a `#define drawMap foo` being evaluated in `adventure.cpp/h` but not in `main.cpp`? – Frédéric Hamidi Aug 26 '13 at 13:57
  • 2
    Try to "clear" your project, delete any old *.o file. What is your compilation command line ? – johan d Aug 26 '13 at 13:57
  • Also make sure the files get *saved*. – R. Martinho Fernandes Aug 26 '13 at 13:59
  • You sure you didnt do something like a.drawMap; instead of a.drawMap()? – skimon Aug 26 '13 at 14:00
  • @FrédéricHamidi I doubt so, as I have had this specific function working yesterday. letter for letter, character for character the EXACT same. – Rijnhardt Aug 26 '13 at 14:00
  • Either you are suffering from some precompiled headers madness, or something is wrong in your IDE, or you copied it omitting some typo in your original code. In any case, your code is correct and should compile. You could consider creating a brand new project and pasting everything there, or changing your development environment. This code _must_ compile. – Daniel Daranas Aug 26 '13 at 14:00
  • @R.MartinhoFernandes I am making sure, by going File>Save Everything – Rijnhardt Aug 26 '13 at 14:01
  • @DanielDaranas What do you suggest I do, sir? – Rijnhardt Aug 26 '13 at 14:02
  • 1
    @Rijnhardt IDE's are tools - if this one doesn't do what you want, use another one. – Daniel Daranas Aug 26 '13 at 14:02
  • 1
    Apart from deleting object files and recompiling as was suggested already, I would also recommend using `#pragma once` or include guards. – lapk Aug 26 '13 at 14:03
  • @DanielDaranas I was using Dev-Cpp for quite a while and a friend recommended Code::Blocks. – Rijnhardt Aug 26 '13 at 14:03
  • @Rijnhardt But Code::Blocks does not compile your valid code. So? I have no further specific suggestion. It _must_ compile - if it doesn't, it's broken. – Daniel Daranas Aug 26 '13 at 14:04
  • Code::BLocks is fine, the compiler may be the problem what compiler are you using?? Try to reinstall it, though I doubt it is because of compiler – khajvah Aug 26 '13 at 14:04
  • Are you compiling it all together or linking at the end? [This is why I HATE IDEs for simple stuff.....] – Jiminion Aug 26 '13 at 14:04
  • @Rijnhardt Again, look at the options to see if you can disable anything resembling precompiled headers. – Daniel Daranas Aug 26 '13 at 14:05
  • @Jim I am under the impression that it is doing that. My compiler at the moment is the GNU GCC Compiler.. I can change it easily. Any recomendations? – Rijnhardt Aug 26 '13 at 14:06
  • @Rijnhardt GNU GCC under windows ?? – khajvah Aug 26 '13 at 14:07
  • @Rijnhardt Another suggestion is that you move your function declaration to just above getMapSize(), which seems to be "recognized". You could also play with changing its name. Crazy suggestions for crazy problems. – Daniel Daranas Aug 26 '13 at 14:07
  • Have a look at the preprocessor output (using the compiler option `-E`) and look for your `drawMap` there! – Dietmar Kühl Aug 26 '13 at 14:08
  • Code compiles fine, it must be settings with your IDE – Paddyd Aug 26 '13 at 14:08
  • 1
    @DanielDaranas Way ahead of you, sir. I did try to chop and change it to my will. Still no luck. I am going to do as you suggested earlier, moving it ALL to a new project. Hopefully this will work. – Rijnhardt Aug 26 '13 at 14:09
  • 1
    Jeez, people. Code::Blocks is a decent IDE and compilers don't just reject trivial code for no reason. The mistake is on OP's part. – jrok Aug 26 '13 at 14:10
  • @jrok Not if his code is _exactly_ as he pasted it here. – Daniel Daranas Aug 26 '13 at 14:11
  • @jrok Finally... I was waiting for this comment but he said he is using GNU gcc under windows?? how is that even possible? – khajvah Aug 26 '13 at 14:11
  • @jrok Must be. I see no other reason. Do you see any problems that stand out? – Rijnhardt Aug 26 '13 at 14:11
  • @khajvah Ever heard of [MinGW](http://www.mingw.org)? That's how. – Goksel Goktas Aug 26 '13 at 14:13
  • If you can get to a command line, type g++ -o advent adventure.cpp main.cpp You may need -I to show it where the include files are. – Jiminion Aug 26 '13 at 14:13
  • @GokselGoktas MinGW is written as MinGW in codeblocks as I remember and there can be confusion because GNU gcc option is available under windows I think but it wouldn't even start to compile so that's not the problem – khajvah Aug 26 '13 at 14:13
  • @khajvah It still doesn't change the fact that it is a port of the GNU compiler toolkit (GCC) to Windows. Also, surely people don't think it's the IDE's or the compiler's fault, right? – Goksel Goktas Aug 26 '13 at 14:16
  • 1
    @GokselGoktas Code has no problems and it is copied and pasted ... – khajvah Aug 26 '13 at 14:18
  • 2
    @GokselGoktas Yes, people do think that, because the code is correct. It may be the IDE, the compiler or their _configuration_. But the code _must_ compile. – Daniel Daranas Aug 26 '13 at 14:20
  • @Rijnhardt Check Project->Properties menu, *Build targets* tab. See if all your cpp files are listed and checked in *build target files* (Note that you probably have two targets, Release and Debug). Also, check the Project tab on the left to see if you're compiling the right one and that the files in files tree are as what they should be. Now, as I said, hit CTRL+F11 to rebuild all files. It *should* work. – jrok Aug 26 '13 at 14:24
  • 1
    The code (above) compiles and runs with: g++ -o advent adventure.cpp main.cpp, so the problem must be with the IDE or configuration. NOTE: It does NOT build with gcc. – Jiminion Aug 26 '13 at 14:27
  • @Rijnhardt Also, [this question](http://stackoverflow.com/questions/10803918/undefined-reference-to-sdl-main/10821071#10821071) is somehow related and could help. – jrok Aug 26 '13 at 14:28
  • 1
    @jrok, if that was the case, he'd get an error about setMapSize() first, unless he left that off of the description. main.cpp:(.text+0x11): undefined reference to `adventure::adventure()' main.cpp:(.text+0x22): undefined reference to `adventure::setMapSize(int)' main.cpp:(.text+0x2e): undefined reference to `adventure::drawMap()' main.cpp:(.text+0x3f): undefined reference to `adventure::~adventure()' main.cpp:(.text+0x52): undefined reference to `adventure::~adventure()' – Jiminion Aug 26 '13 at 14:31
  • 1
    My guess now is he's compiling with an earlier version of adventure.cpp which has no drawMap function in it (it's at the end of the file). [It has to be something odd and silly at this point...] – Jiminion Aug 26 '13 at 14:33
  • @DanielDaranas I didn't mean the problem wouldn't be with the way he uses the compiler or the IDE. My point was that, I very much doubt a bug in the IDE or the compiler would be leading to this kind of a behavior. And yes, my guess is the same as that of Jim; that the OP is just doing something wrong. – Goksel Goktas Aug 26 '13 at 14:53
  • Thanks all for the help and advice. I have gone about the task of rewriting everything. (hopefully it wasn't big) But I am faced with a even weirder problem now, my classes being duplicated for some very odd reason. I am consulting with a friend, if he cannot help, ill start a new question here. – Rijnhardt Aug 26 '13 at 14:58
  • 3
    @Rijnhardt: Your class is "being duplicated"? That doesn't mean anything; an actual error message would. Do you have an [include guard](http://en.wikipedia.org/wiki/Include_guard) in your header? (Someone suggested `#pragma once`; that's not portable and not recommended.) – Keith Thompson Aug 26 '13 at 15:03
  • Keith is actually Ken Thompson's love child, so he's well worth listening to. :) [It's some kind of IDE setup problem, methinks.] – Jiminion Aug 26 '13 at 15:14
  • @Rijnhardt Classes "being duplicated"? What do you mean? You are having very serious problems with your environment. – Daniel Daranas Aug 26 '13 at 15:19
  • Thanks all. Do not worry, it was a silly mistake on my side.. All is fixed now. Have a good evening! – Rijnhardt Aug 26 '13 at 17:10
  • Now worried. what was the problem? – sr01853 Aug 27 '13 at 11:08

0 Answers0