Isnt working on code block, why? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Isnt working on code block, why?

I put the same set up in code::block and its telling me 'setName' was not declared in this scope. But works fine if I run it in app 😐 also another thing I get error is if I put int a; a = 15; its says there not data type but work fine in app. is it different compiler that's y?

1st Mar 2017, 11:40 AM
Jonathan
7 Answers
+ 9
Can't really tell without inspecting the entire code. Normally, codes which run on CodePlayground should run on desktop compilers as well. It's the other way around that gives rise to problems.
1st Mar 2017, 12:55 PM
Hatsy Rei
Hatsy Rei - avatar
+ 9
Lol Jonathan. Replace setName with setVar.
1st Mar 2017, 2:13 PM
Hatsy Rei
Hatsy Rei - avatar
+ 9
Happens all the time though. Glad I helped.
1st Mar 2017, 2:21 PM
Hatsy Rei
Hatsy Rei - avatar
+ 1
#include <iostream> #include <string> /*#include "SoloLearningClass.h"*/ using namespace std; class BankHolding{ public: int a = 15; int b = 15; int sum = 5; void setVar(int a){ } void AddBoth(){ cout << a + b << endl;} void MoreToo(){ cout << sum << endl; } }; class BankChecking{ public: int c = 20; int d = 20; int sum = 40; void LookFor(){ if (sum == c + d){ cout << "Same" << endl; } else { cout << "Not Same" << endl; } } }; class AllAcount{ public: AllAcount(string nm){ setName(nm); // getting error in code::Block error 'setName' was not declared in this scope } void setVar(string x){ name = x; } string getVar(){ return name; } private: string name; }; class BankAccount { public: void sayHi(){ cout << "Hi" << endl; } }; int main() { BankHolding hold; BankHolding NumberAs; BankHolding Data; Data.setVar(33); NumberAs.MoreToo(); hold.AddBoth(); BankChecking getlook; getlook.LookFor(); AllAcount Info1("Jo"); AllAcount info2("Bill"); cout << info2.getVar(); BankAccount test; test.sayHi(); /* "SoloLearningClass obj;*/ return 0; }
1st Mar 2017, 1:50 PM
Jonathan
+ 1
@Hatsy Rei *blushes* Omg I can't believe I didn't see something so simple T-T been up all night going threw the course xD I'm on meltdown. Thank you very much for the help @Hatsy Rei 👍
1st Mar 2017, 2:19 PM
Jonathan
0
@Hatsy Rei https://code.sololearn.com/cbqWHwbGgBPa/?ref=app that code fine in app but gives error in code::block
1st Mar 2017, 1:19 PM
Jonathan
0
@Hatsy Rei https://code.sololearn.com/ciFa177SQ6Vc/?ref=app nvm getting same error in app also if someone can look over it and see what's wrong and explain would be awesome :) ty
1st Mar 2017, 1:44 PM
Jonathan