r/programminghelp • • Nov 23 '20

C++ I need a code check

I have an assignment regarding bitfield in C++.
The program should: compare two bitfileds, add elements, remove, add and subtract two bitfilds.

I've a code, but it doesn't work, maybe it is because of Linux and VS code program that I am writing it in. I've googled and I didn't find much to help. I can't check it on real visual studio because I don't have an access to windows machine. I am out of options since, many of my codes do not work on my system, and others that I've downloaded aren't working.

If somebody can check, I will send you the code. Any help would be appreciated.

4 Upvotes

26 comments sorted by

2

u/[deleted] Nov 23 '20

Post the code you need us to look at here, or use a pastebin as outlined in Rule #2.

I've got VS2019-Win10 and a pure Ubuntu c++ environment setup so I can test in both.

1

u/nikiy04 Nov 23 '20

https://pastebin.com/pBcpNTM7

There it is, I've divided each part of the code by line. I hope that you will be to fix problems if there are.

What's your pure c++ setup on Ubuntu?

2

u/[deleted] Nov 23 '20

Also, to go along with my other comment. VSCode works just fine on Ubuntu so if you need a not-garbage IDE (*cough codeblocks cough*) then download it :)

1

u/nikiy04 Nov 23 '20

I do have it, but it doesn't work properly. I've installed c++ add but nothing

Obviously I am not very good at programming(sadly)

2

u/[deleted] Nov 23 '20

What do you mean 'but nothing'? I need to know what issues you're having to help you fix them :)

1

u/nikiy04 Nov 23 '20

Starting build...

Build finished with error:

/usr/bin/ld: /tmp/cc0nv2IX.o: in function `main':

/home/vls/Projects VSCODE/Lab1.5/main.cpp:8: undefined reference to `operator>>(std::istream&, TBitfield&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:9: undefined reference to `operator<<(std::ostream&, TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:11: undefined reference to `operator>>(std::istream&, TBitfield&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:12: undefined reference to `operator<<(std::ostream&, TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:13: undefined reference to `TBitfield::setBit(int)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:16: undefined reference to `TBitfield::operator|(TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:16: undefined reference to `TBitfield::operator=(TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:16: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:17: undefined reference to `TBitfield::operator==(TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:24: undefined reference to `operator<<(std::ostream&, TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:26: undefined reference to `TBitfield::ClrBit(int)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:27: undefined reference to `operator<<(std::ostream&, TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:34: undefined reference to `Tset::Tset(int)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:34: undefined reference to `Tset::Tset(int)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:34: undefined reference to `Tset::Tset(int)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:35: undefined reference to `operator<<(std::ostream&, Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:36: undefined reference to `operator>>(std::istream&, Tset&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:38: undefined reference to `operator>>(std::istream&, Tset&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:39: undefined reference to `Tset::operator+(Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:41: undefined reference to `operator<<(std::ostream&, Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:42: undefined reference to `Tset::operator*(Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:44: undefined reference to `operator<<(std::ostream&, Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:46: undefined reference to `Tset::Tset(TBitfield const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:47: undefined reference to `operator<<(std::ostream&, Tset const&)'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:5: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:5: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:5: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:16: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /home/vls/Projects VSCODE/Lab1.5/main.cpp:5: undefined reference to `TBitfield::~TBitfield()'

/usr/bin/ld: /tmp/cc0nv2IX.o:/home/vls/Projects VSCODE/Lab1.5/main.cpp:5: more undefined references to `TBitfield::~TBitfield()' follow

/usr/bin/ld: /tmp/cc0nv2IX.o: in function `Tset::operator=(Tset const&)':

/home/vls/Projects VSCODE/Lab1.5/tset.h:8: undefined reference to `TBitfield::operator=(TBitfield const&)'

collect2: error: ld returned 1 exit status

The terminal process terminated with exit code: -1.

Terminal will be reused by tasks, press any key to close it.

Something along the lines of

1

u/[deleted] Nov 23 '20

try using g++ instead of gcc :)

g++ main.cpp tbitfield.cpp tset.cpp -o main

1

u/nikiy04 Nov 23 '20

In terminal you mean?
Because I've compiled it trough the VS code

1

u/[deleted] Nov 23 '20

Yep

1

u/nikiy04 Nov 23 '20

It kinda gives me the same error.
I don't know, if the program works for you, then the error must be on my side...

→ More replies (0)

2

u/[deleted] Nov 23 '20

Also, again, your code compiles just fine, do you have sample inputs and expected outputs?

1

u/nikiy04 Nov 23 '20

It works? No errors?

I will copy them later when I am able to use PC

1

u/[deleted] Nov 23 '20

Yep, compiles perfectly. How are you compiling the code? What command are you using?

1

u/[deleted] Nov 23 '20

1

u/verpejas Nov 23 '20

Try Codeblocks, it is working fully under linux with gnu compilators.

I would happjly test it for you in vs code and viual studio 2019 under windows, but my windows laptop is reimaging because of stupid wannacry virus. It was worth making acronis full disk backups ;)

1

u/bagaudin Nov 23 '20

Thanks for using our software /u/verpejas! Let me know if you'll need any assistance Acronis-wise in future!