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 Faha Sharapov · March 24, 2015
I got an error: "cout was not declared in this scope."   -->   are you adding using namespace std; above your int main ()   ?

"In fact, I cannot run any program which requires to place classes in separate files."   -->   if you are using codeblocks, go to Setting/Compiler/Build Options  and then check the Explicitly add currently compiling file's... You should be good then...
0 Ehsanul Haque Kanan · March 24, 2015
Hi Faha,

Thanks for your response. I was not using "using namespace std." That's why, the error was showing. But despite I include it, I still cannot run the program. Now a new error has appeared, stating "no such file or directory" in 2main.

I have also checked the " Explicitly add currently compiling file's" option. But still the program doesn't run.

Here are my codes:

Codes of main.cpp:

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

int main()
{
    Sally sallyObject;
    sallyObject.printCrap();

}




Codes of sally.h:

#ifndef SALLY_H
#define SALLY_H


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

#endif // SALLY_H


Codes of sally.cpp:
#include "Sally.h"
#include <iostream>
using namespace std;

Sally::Sally()
{

}

void Sally::printCrap()
{
cout<<"Did someone say steak"<<endl;

}

It would be highly appreciated if you help me to solve the issue. :)

Thanks in advance.
0 Brian Reed · March 24, 2015
Hi Ehsanul,

You're not alone! I too am having issues with this two tutorials.

I'm using Code Blocks 13.12, but the tutorial it was ver 10.something.

So, it must be something different we have to do or check for with this version. I skipped the first one, as I just wonted to move on. I think I'll do the same for this one too. However, at some point this will be a good thing to learn and when we figure out what went wrong here, we'll be the better for it.

On build and run I get these errors:

main.cpp biuld log
_________________________________________________________________________
mingw32-g++.exe  -I"C:\Program Files (x86)" -IC:\Users\user\Desktop\C++ -c C:\Users\user\Desktop\C++\main.cpp -o C:\Users\user\Desktop\C++\main.o
mingw32-g++.exe  -o C:\Users\user\Desktop\C++\main.exe C:\Users\user\Desktop\C++\main.o   
C:\Users\user\Desktop\C++\main.o:main.cpp:(.text+0x4d): undefined reference to `Sally::Sally()'
C:\Users\user\Desktop\C++\main.o:main.cpp:(.text+0x58): undefined reference to `Sally::printCrap()'
collect2.exe: error: ld returned 1 exit status

main.cpp biulld message
_____________________________
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()'|


Sally.cpp biuld log (When run separately)
__________________________________
mingw32-g++.exe  -I"C:\Program Files (x86)" -IC:\Users\user\Desktop\C++ -c C:\Users\user\Desktop\C++\Sally.cpp -o C:\Users\user\Desktop\C++\Sally.o
mingw32-g++.exe  -o C:\Users\user\Desktop\C++\Sally.exe C:\Users\user\Desktop\C++\Sally.o   
C:\Users\user\Desktop\C++\Sally.o:Sally.cpp:(.text+0xf): undefined reference to `Sally::printCrap()'
c:/program files (x86)/codeblocks/mingw/bin/../lib/gcc/mingw32/4.7.1/../../../libmingw32.a(main.o):main.c:(.text.startup+0xa7): undefined reference to `WinMain@16'

Sally.cpp biuld message (When run separately)
_____________________________________

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

c:\program files (x86)\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.7.1\..\..\..\libmingw32.a(main.o):main.c:(.text.startup+0xa7)|
|undefined reference to `WinMain@16'| <<-----I think this has something to do with my problem
0 Faha Sharapov · March 24, 2015
Ehsanul Haque Kanan   -  will get back to you in few hours...

Brian Reed   -   go to Setting/Compiler/Build Options and then check the Explicitly add currently compiling file...  The error with WinMain@16  needs to be resolved then...
0 Dol Lod · March 24, 2015
I checked your code directly substituting things in and it worked perfectly on ideone.com.
0 Ehsanul Haque Kanan · March 24, 2015
Hi Brian,

Thanks for your response. I believe that we must get a solution to this issue before moving to the next tutorials, as there are so many lessons which require working with classes with multiple files. If we skip it, we will definitely fall into a huge trouble! :(

This issue happens not only on Code Blocks v13.12, but also on v10! 

I hope that someone will solve this issue very soon to help us proceeding further with Bucky's C++ tutorials. :)

Bucky, can you help us??
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 Faha Sharapov · March 25, 2015
Brian, post your code and let's see why it's giving you these errors.
  • 1
  • 2

C++

106,930 followers
About

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

Links
Moderators
Bucky Roberts Administrator