Programming

You should solve them in C++. Get your daughter into them too. I worked on last year’s problems when i was learning JavaScript, and it was a good way to get some motivation to poke around into various language features (like the lolJS mod bug…).

1 Like

Programmer who moderately enjoys arts, crafts, and human interactions desired. Two out of three will do.

Hmm. Would be in but the Venn diagram of “into programming” and “creative type; can come up with a fun and interesting exercise” has very small intersection. Trying to think of a toy exercise that would interest people.

I need to learn how to trust myself more. I always have an “oh shit oh shit oh shit” moment when asked about something or asked to update something from 3+ months ago because the context is completely out of my mind and I’m worried I left it in a complete mess.

Instead I usually find it tidily and nicely packaged for me to come back to. Idk why I always panic or feel reluctant to go back to stuff I did a while ago. I usually dot my i’s and cross my t’s.

1 Like

https://mobile.twitter.com/danoot/status/1334967635318956034

1 Like

Dog Dancers

https://mobile.twitter.com/ViolenceWorks/status/1335382435031252992

1 Like

c++ problem. This is an except that recreates an error

I think this is a problem with not understanding the compiler/linker. This is on windows with g++.

VectorTest.h file

#include <iostream>
#include <string>
#include "Sequence.h"

namespace CS52
{
  class Vector : public Sequence
  // class Vector
  {
    public:
      Vector();                       //default constructor
      Vector(int size, int int_val);  // overloaded constructor

    private:
      int _size = 0;
      int _capacity = 0;
      int* _data = nullptr;
  }; //Vector class
} //namespace

VectorTest.cpp file

#include <iostream>
#include <string>
#include "VectorTest.h"

namespace CS52
{
  Vector::Vector()
  {
    std::cout << "default constructor\n";
  };

  Vector::Vector(int size, int int_val)  // overloaded constructor
  {
    _size = size;
    _capacity = size;
    _data = new int[size];
    for (int i = 0; i < size; i++)
    {
      _data[i] = int_val;
    }
  };

} // end namespace CS52

SequenceTest.h file

#include <iostream>
#include <string>

namespace CS52
{
  class Sequence
  {
    public:
      virtual int size() const = 0;
      virtual int capacity() const = 0;
      virtual std::string type() const = 0;
      virtual ~Sequence() {}
  };
}

A05Test.cpp file

#include <iostream>
#include <string>
#include "Vector.h"

void info(CS52::Vector& v);

int main()
{
  CS52::Vector(5, 3);
  return 0;
} //main

compile command

g++ A05Test.cpp VectorTest.cpp -o A05Test.exe

error

C:\Users\jayne\AppData\Local\Temp\cciChZFF.o:A05Test.cpp:(.text+0x38): undefined reference to `CS52::Vector::~Vector()'
collect2.exe: error: ld returned 1 exit status

Had this working when Vector Class was on it’s own, but part of the assignment here is making the Vector Class a subclass of Sequence. And I think that with the virtual functions in Sequence you’re not supposed to need a cpp file, but ??? I don’t know if including the SequenceTest.h file in the VectorTest.h file is right or if it should be enough for the compiler/linker.

Thanks for looking at this if you do and sorry for this, but I’m at’ing @goofyballer and @ChipsAhoy - both C++ dudes, but I’ll be grateful for any help from anyone.

:pray:

  1. You have #include “Vector.h” and #include “Sequence.h” but your files are named VectorTest.h and SequenceTest.h – I’m guessing you use both names and didn’t change everywhere?

  2. Where (in which cpp) is virtual ~Sequence() {} defined? Code in headers is funny. It’s easy to add the same implementation to multiple files when you #include. Then what is the linker supposed to do?

If your problem wasn’t solved by the filename, move the implementation Sequence::~Sequence() {} to a cpp file.

To clarify: you have a virtual destructor in the base class. you don’t override it in the derived class. So the dervived vtable entry should point to Sequence::~Sequence, but the linker can’t find it.

Really appreciate the help. The missing “Test” stuff was an artifact of me trying to eliminate extraneous stuff for you guys to look at. That was a mistake because I got it to compile by correcting something that wasn’t shown. There was another function that was declared and not defined. The thing was, the error was exactly the same. The error messages I’ve found to generally suck, but I guess these linker error message especially suck.

Still, I’m surely misunderstanding stuff and your answers were helpful in getting me somewhere near understanding this stuff.

Some of this class being hard like this is that there was a C class that was a prereq that my daughter skipped (and I never did) because she did an AP class, but that class was in javascript.

Thanks again.

This book is a quick read and a solid foundation in C.

1 Like

Makefile syntax is really annoying. I had to do a lot of work with C and Makefiles in my last job.

A lot of things in C/C++ are done either because that’s the way it’s been done for 40 years and it ain’t gonna change, or for efficiency/speed. I don’t argue.

Chips, is C++ mostly what you’re doing for a living?

Chips and Goofy,

What do you guys do generally? Game development? General apps? Backend support for search?

I don’t really know if I understand how this works well enough to successfully make this snarky comment, but…

Template classes and overloading operators are cool. If I do enough of that stuff I think I can turn C++ into Python!

Now that you’ve had a taste of C++ - you should appreciate learning Java or C#. They’re both C++ w/o all the painful compiling/cross-platform stuff. They keep you out of trouble in a lot of other ways. C++ with guardrails.

Learn Rust instead! It’s C++ except the compiler tells you when you do something wrong. Also the unsigned 64-bit integer type is u64 rather than unsigned long long int.

1 Like

Rust is awesome. Want to learn more, but I dont know what to do with it yet.

I irrationally love Python and you need JavaScript for the web and everything I think of seems to be web stuff, so for my own stuff Python/Javascript/react just seems obvious.

As far as any third language that I might some day do as work for someone else, I’m pretty sure I can figure out the difficulties of c++, so they are a good thing (barrier to entry) considering there’s sooooo much c++ in the world. Also, not being a new thing like rust is probably good if you’re old and not wanting to be discriminated against. There was a COBOL programmer on 2p2 who got work. It probably helped that he was older.

I’m going to be taking another class in C + + next semester anyway, data structures in C + +, so I’m getting pretty far in no matter what. Nanodaughter was really not prepared for these classes and needs the help and I can’t help without just taking the class along with her. ( you’re allowed to work together on assignments, she takes the tests, but we study together, and because of zoom and it’s a night class I get to go to lecture too)

https://twitter.com/qntm/status/1338941371143614466

2 Likes

I’ve always said that’s why I will never go into management. As an engineer I can piss on the boss’s desk and he has to just smile and take it.

I want to be the one doing the pissing not the one getting pissed on.