Need Help on C++ Tutorial 15 and 42

0 Ehsanul Haque Kanan · March 23, 2015
Hi,

I cannot run the programs of the 15th and the 42nd tutorial of Bucky's C++ tutorial series. I got an error: "cout was not declared in this scope." 

In fact, I cannot run any program which requires to place classes in separate files.

Please, help me. I am new to C++. I am totally stuck! :(

Thanks in advance.

Post a Reply

Replies

- page 1
Oldest  Newest  Rating
0 Ehsanul Haque Kanan · March 24, 2015
Hi Faha,

I hope that I will get a great solution from you. I am waiting for your next message. :)
0 Faha Sharapov · March 24, 2015
Sorry buddy, was kind of busy doing other things...
I don't see any problem in your code. I tested it, it works fine. Codeblocks version I am using is 13.12 (not sure if this is the reason why it's not showing on your end)
0 Brian Reed · March 25, 2015
Thanks Faha, I tried the explicit settings and no joy. I dropped in Sally (also sally.h) under the compiler/ #Defines and had the best improved results ( line error numbers are as per code, and code as per tutorial).

Here are the new errors (gives me hope to find fault):
C:\Users\user\Desktop\C++\Sally.h|4|error: expected identifier before numeric constant|
C:\Users\user\Desktop\C++\Sally.h|4|error: expected unqualified-id before numeric constant|
C:\Users\user\Desktop\C++\main.cpp||In function 'int main()':|
C:\Users\user\Desktop\C++\main.cpp|7|error: expected ';' before 'sallyObject'|
C:\Users\user\Desktop\C++\main.cpp|9|error: 'sallyObject' was not declared in this scope

Ehsanul, will get through this one way or another, worst case is to find a work around.


Cheers,
Brian 
0 Ehsanul Haque Kanan · March 25, 2015
Hi Faha,

I am also using version 13.12.
0 Faha Sharapov · March 25, 2015
Brian, post your code and let's see why it's giving you these errors.
0 Ehsanul Haque Kanan · March 25, 2015
Will no one be able to solve this issue?:'(
0 Brian Reed · March 25, 2015
Faha,
Here is the code


main.cpp
#include <iostream>
#include "Sally.h"
using namespace std;

int main(){

    Sally sallyObject;

    sallyObject.printCrap();

}

Sally.h
#ifndef SALLY_H
#define SALLY_H


class Sally
{
    public:
        Sally();
        void printCrap();
    protected:
    private:
};

#endif

Sally.cpp
#include "Sally.h"
#include <iostream>
using namespace std;

Sally::Sally()
{
}
void Sally::printCrap(){
    cout << "Smells like Steak!" << endl;
}
_________________________________
These are the current build message errors I get (after build & run, while main.cpp tab in view).

C:\Users\user\Desktop\C++\main.o:main.cpp|| undefined reference to `Sally::Sally()'|
C:\Users\user\Desktop\C++\main.o:main.cpp|| undefined reference to `Sally::printCrap|

Previous errors mentioned were what I got after going to the compiler settings and dropping Sally into the #Defines tab.
The ones you now see, are after build & run without anything in the #Defines tab.

So, I'm thinking it might be as you alluded to before (where Code Blocks is looking for things).

Cheers,
Brian
0 Brian Reed · March 25, 2015
Ha! I fixed it!

Thanks Faha for the insights!

I first started using Code Blocks for "C" programming and thought to myself (should have shared that, my bad), maybe that has something to do with the problem, but said na, ...it can't be that. I was wrong. I created a project in "C", but never in "C++" and in doing Bucky's tutorials I never created a new project, just files to work on. So, with the playing around I was doing to fix this one I was slowly absorbing the hints and then I said "I have to try creating a new project in C++, because maybe, just maybe, code blocks references (the ones we can't see) are setup based on the projects we open.

Viola!, that was it.

Ehsanul, Create a new project (select the empty project) and once created just right click on it and add the files you already made and you should be able to Build and run it! Hope this works out for you.

Cheers,
Brian
 
0 Faha Sharapov · March 25, 2015
Hi guys,
I was gonna send you the following, but Brian, good for you, you resolved it by yourself.

Let's go over it again then

1. Create a new Project -> Console Application -> C++ -> ProjectName -> Next -> Finish

2. Create a new Class -> Sally -> Uncheck Virtual destructor, Uncheck Has destructor -> Check Header and implementation file shal be in same folder -> Create -> OK -> OK

And insert your code into each file...
0 Ehsanul Haque Kanan · March 26, 2015
Hi everyone,

I have found a solution. Go to Settings>Compiler>Reset Defaults. Then click OK. Any program with classes in multiple files will run with perfection! 
  • 1
  • 2

C++

107,334 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator