• 0

c++ Help


Question

20 answers to this question

Recommended Posts

  • 0

From what I understand, you want to add a  date of birth into the Person class.

 

Step 1

To begin, you'll need to add a date of birth field into the person class. You'll need to do this in two parts.

 

First, you need to include the OCCCDate class header file inside your Person.h header file...

 

Person.h
---------------------------------------------------------

//Person.h

#ifndef PERSON_H
#define PERSON_H
#include<string>

// Add the OCCCDate.h header file...
#include "OCCCDate.h"

...

Once you've added the header file, you can create a private class member inside your person class like you've described in your original post.

 

Person.h
---------------------------------------------------------

...

class Person{
    private:
        string firstname;
        string lastname;

        // Add an OCCCDate class here as a member, just like you did for the strings above.

    public:

...    
Step 2:

It's unlikely that you'll want a person to have the current system date as their date of birth, so you'll need to add a parameter to the Person constructor to pass a date of birth. like this:

Person.h
---------------------------------------------------------

...

class Person{

    private:
        ...

    public:
        Person(string firstName, string lastName, OCCCDate dateOfBirth);
//                                                ^--------,---------^
//                                                         New parameter in the constructor.

...    
Don't forget you'll need to copy the date of birth parameter in the constructor in your Person.cpp file too! Looking at your .cpp file, you're almost there already :)).

Once you've done that, you can add a method to the Person class to retrieve the date of birth (just like Person::getFirstName() and Person::getLastName()), and you're good to go!

Hope this helps :)

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595929151
Share on other sites

  • 0

I assume you're seeing an error talking about "redefinition of class OCCCDate"? That's because of the following lines in OCCCDate.h...

 

//file OcccDate.h

#ifndef OCCCDATE_H
#define OCCCDDATE_H
See the spelling mistake in the #define line (hint: two 'D's in DDATE)? You'll need to fix that like this...

 

//file OcccDate.h

#ifndef OCCCDATE_H
#define OCCCDATE_H
Once you fix that, it should work. Because of the spelling mistake, the #ifndef block was always TRUE (because OCCCDATE_H was never defined), and the compiler tried to define the class again, which is bad ;).
Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595930801
Share on other sites

  • 0

Or you could just use #pragma once rather than #ifndef #define #endif. All major compilers (MSVC, GCC, Clang, Intel, etc.) support it and it reduces the potential for bugs. Like the one you just had.

While I agree with you in practice, if it's an assignment it may be that the tutor is sticking strictly to the standard, and using #pragma vs a standard-compliant alternative may lose the student points.

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.

Indeed it is, but its also incredibly gratifying if you enjoy it. Glad your issue is sorted. :)

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595931131
Share on other sites

  • 0

WOW just that small mistake and it took me 3 days. jesus. programming is so hard.

No, C++ is just ****. No decent programming language uses header files and silly macro tricks just to get programs to compile. Don't let your opinion of programming be tainted by the arcane and irrelevant rules of C++, even though it happens that this is what your teacher misleadingly thought would be a good idea to show you first. If your teacher thinks C++ is good just ask him "why are there header files in C++?" and watch him be embarassed. I fondly remember being unable to receive an intelligent answer to this question in my first programming class.

 

It ****es me off to think many people must quit programming simply because they're being shown the most bizarre and capricious language in existence first, and assume that all programming must be like that. It's not.

 

Arm yourself with courage and a good C++ book (I used The C++ Primer Plus by Stephen Prata), and when you're through with this course, take a look at such beautiful languages as Python, C#, F#, Scala, Rust, etc. I guarantee your outlook on programming will change for the better and dramatically so.

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595931753
Share on other sites

  • 0

No, C++ is just ****. No decent programming language uses header files and silly macro tricks just to get programs to compile. Don't let your opinion of programming be tainted by the arcane and irrelevant rules of C++, even though it happens that this is what your teacher misleadingly thought would be a good idea to show you first. If your teacher thinks C++ is good just ask him "why are there header files in C++?" and watch him be embarassed. I fondly remember being unable to receive an intelligent answer to this question in my first programming class.

 

It ****es me off to think many people must quit programming simply because they're being shown the most bizarre and capricious language in existence first, and assume that all programming must be like that. It's not.

 

 

That said, he didn't exactly help himself with that function name. VERY easy to mistype that, so I'm not at all surprised he didn't spot it...

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595931945
Share on other sites

  • 0

That said, he didn't exactly help himself with that function name. VERY easy to mistype that, so I'm not at all surprised he didn't spot it...

At least when you mistype something in most programming languages, you tend to get something from the compiler like "hey what's that you typed in file (Z) at line (X) column ( Y), I have no idea what that is." In C++ you tend to get the equivalent of "AAAAAAaaaaarglgl.... guh." Much of the difficulty consists of learning how to map the gibberish to actual errors.

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595932521
Share on other sites

  • 0

At least when you mistype something in most programming languages, you tend to get something from the compiler like "hey what's that you typed in file (Z) at line (X) column ( Y), I have no idea what that is." In C++ you tend to get the equivalent of "AAAAAAaaaaarglgl.... guh." Much of the difficulty consists of learning how to map the gibberish to actual errors.

 

Pretty much why I walked away from C/C++ 2 decades ago. :p  Sure it's handy, but it's a pain in the backside, too!

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595932537
Share on other sites

  • 0

At least when you mistype something in most programming languages, you tend to get something from the compiler like "hey what's that you typed in file (Z) at line (X) column ( Y), I have no idea what that is." In C++ you tend to get the equivalent of "AAAAAAaaaaarglgl.... guh." Much of the difficulty consists of learning how to map the gibberish to actual errors.

 

That is why I use Clang for my C and C++ work when possible: its error messages are so much more sane than GCC. In my opinion one of the biggest advantages of Visual Studio's C++ compiler over GCC is its error messages. That said, I think that Clang beats them both by a long shot with exceptionally helpful diagnostic messages. I was going to try to demonstrate Clang's superiority in this regard using the author's code, but it didn't actually make that much of a difference. For the record, the results are as follows:

$ make CXX=g++
g++ -c -std=c++11 -w -O3   Person.cpp -o Person.o
g++ -c -std=c++11 -w -O3   OCCCDate.cpp -o OCCCDate.o
g++ -c -std=c++11 -w -O3   TestOCCCDate.cpp -o TestOCCCDate.o
In file included from Person.h:7:0,
                 from TestOCCCDate.cpp:4:
OCCCDate.h:8:7: error: redefinition of ?class OCCCDate?
In file included from TestOCCCDate.cpp:3:0:
OCCCDate.h:8:7: error: previous definition of ?class OCCCDate?
make: *** [TestOCCCDate.o] Error 1

$ make CXX=clang++
clang++ -c -std=c++11 -w -O3   Person.cpp -o Person.o
clang++ -c -std=c++11 -w -O3   OCCCDate.cpp -o OCCCDate.o
clang++ -c -std=c++11 -w -O3   TestOCCCDate.cpp -o TestOCCCDate.o
In file included from TestOCCCDate.cpp:4:
In file included from ./Person.h:7:
./OCCCDate.h:8:7: error: redefinition of 'OCCCDate'
class OCCCDate{
      ^
./OCCCDate.h:8:7: note: previous definition is here
class OCCCDate{
      ^
In file included from TestOCCCDate.cpp:4:
In file included from ./Person.h:7:
./OCCCDate.h:15:12: error: expected member name or ';' after declaration specifiers
                OCCCDate();//default constructor, uses current system date and time
                ~~~~~~~~ ^
./OCCCDate.h:16:12: error: expected member name or ';' after declaration specifiers
                OCCCDate(int day, int month, int year);//as define above
                ~~~~~~~~ ^
./OCCCDate.h:16:12: error: expected ')'
./OCCCDate.h:16:11: note: to match this '('
                OCCCDate(int day, int month, int year);//as define above
                        ^
4 errors generated.
make: *** [TestOCCCDate.o] Error 1

$ g++ --version
g++ (Debian 4.7.2-5) 4.7.2
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ clang++ --version
Debian clang version 3.0-6.2 (tags/RELEASE_30/final) (based on LLVM 3.0)
Target: x86_64-pc-linux-gnu
Thread model: posix

I can understand why Majesticmerc was able to spot the error whereas nether Clang nor GCC could catch it automatically. Therefore I have to agree with you to some extent. While some compilers do a much better job at printing helpful diagnostic messages than others, it is generally much more difficult to pinpoint errors in C++ than in newer languages like Python. I can generally interpret error messages and pinpoint the mistake in my C++ source code pretty quickly, but I think most of that comes down to experience. I remember Googling basically every error message when I started learning C++ hoping to find the resolution posted somewhere on the Internet. So while I would like to disagree with your assessment, I don't think I realistically can. Therefore I would merely like to point out that Clang prints much better diagnostic messages than other compilers - in most cases.

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595933651
Share on other sites

  • 0

No, C++ is just ****. No decent programming language uses header files and silly macro tricks just to get programs to compile. Don't let your opinion of programming be tainted by the arcane and irrelevant rules of C++, even though it happens that this is what your teacher misleadingly thought would be a good idea to show you first. If your teacher thinks C++ is good just ask him "why are there header files in C++?" and watch him be embarassed. I fondly remember being unable to receive an intelligent answer to this question in my first programming class.

 

It ****es me off to think many people must quit programming simply because they're being shown the most bizarre and capricious language in existence first, and assume that all programming must be like that. It's not.

 

Arm yourself with courage and a good C++ book (I used The C++ Primer Plus by Stephen Prata), and when you're through with this course, take a look at such beautiful languages as Python, C#, F#, Scala, Rust, etc. I guarantee your outlook on programming will change for the better and dramatically so.

 

Seems a bit one sided :).

 

1. If you don't want "silly macro tricks" aka include guards then just never include the header more than once, or use #pragma once ;)

2. Header files are used to define the interface/contract. If you have a header which contains int get_magic_for_this_machine(); then you  call that function, it does some magic, you don't need to know about the 9000 other internal functions and classes it may have/use in its cpp file. Any code in a header file is inlined too. Also its possible to write something that only uses headers... but you'll have to endure huge build times.

3. For his problem there is no way the compiler could help him...

 

#ifdef A

#define B // Was this supposed to be A? or is B correct? What about the stuff below? It could mean anything so this could never be statically checked at build time

#define C

#define D

#endif

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595941813
Share on other sites

  • 0
1. If you don't want "silly macro tricks" aka include guards then just never include the header more than once, or use #pragma once

 

Include guards are still the only standard way, and not including the header more than once in any compilation unit is a very difficult problem to solve in general.

 

2. Header files are used to define the interface/contract.

Not true, they also must include private class members, inline and template function definitions, among other implementation details. The way to define interfaces in object-oriented languages is to use actual interfaces.

 

Header files in C++ are just a legacy of the C compilation model; it's not coincidence that no other language makes use of them.

 

3. For his problem there is no way the compiler could help him...

I agree; the reliance of C and C++ on pre-processor tricks are but one of several issues that make the compiler and tooling very difficult to make user-friendly. The compiler can't report anything meaningful about macros because it doesn't know anything of macros. Well-designed languages take the feasability of tooling into consideration, which apparently wasn't on Stroustrup's mind back then.

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595942153
Share on other sites

  • 0

Include guards are still the only standard way, and not including the header more than once in any compilation unit is a very difficult problem to solve in general.

 

Not true, they also must include private class members, inline and template function definitions, among other implementation details. The way to define interfaces in object-oriented languages is to use actual interfaces.

 

Header files in C++ are just a legacy of the C compilation model; it's not coincidence that no other language makes use of them.

 

I agree; the reliance of C and C++ on pre-processor tricks are but one of several issues that make the compiler and tooling very difficult to make user-friendly. The compiler can't report anything meaningful about macros because it doesn't know anything of macros. Well-designed languages take the feasability of tooling into consideration, which apparently wasn't on Stroustrup's mind back then.

 

For interfaces yes you could use something like

 

class IMyInterface 

{

public:

 virtual ~IMyInterface() { }

 virtual void the_magic() = 0;

};

But if you required data members you wished to be hidden then you can use the PIMPL idiom, but either way someone seeing some basic types or forward declared internal classes in the private section isn't too bad.

Link to comment
https://www.neowin.net/forum/topic/1175399-c-help/#findComment-595947709
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

    • Microsoft Teams is getting a controversial location tracking feature that users may hate by Usama Jawad Image generated with Microsoft Copilot Earlier this year, Microsoft planned to roll out a controversial location tracking feature in Teams, but following customer feedback, it decided to delay its release. The bad news is that the company has decided to launch it later this year, but it's based on roughly the same design that was shared earlier, which means that many users still have good reason to worry. Basically, Microsoft Places and Teams have received workplace check-ins via Wi-Fi. The idea is that if an employee arrives at the office and connects to their enterprise network, their profile status indicator will show them as being present in the office. For example, if you arrive at work, open Teams on your PC, and connect to the "Studio B" company Wi-Fi network, your Teams profile will indicate that you are present in "Studio B", as shown below: Microsoft says that this feature is basically a replacement for physical workplace check-in peripherals, it reduces the need to manually update your status, and it also enables co-workers to know that you're at work so that they can coordinate in-person meetings with you. IT admins can enable this workplace check-in capability at a tenant level, and users have the ability to control whether they want to enable it or not. Of course, all of that sounds great on paper, but naturally, many Teams customers may still have concerns, as they did before. This is because it enables your reporting manager and other members of the organization to track if you are at the office, when you arrive at the office, and where you are right now. This could be problematic for people who work in what they consider to be flexible work environments or hybrid setups, and this kind of location tracking could be considered an invasion of privacy. Microsoft has tried to alleviate some of these concerns by letting users know that they can manually set their location easily, which essentially overrides workplace check-in if they feel uncomfortable with it. However, that doesn't really solve the problem because your organization could enforce a workplace policy that mandates that this feature remains enabled. The Redmond tech giant has also assured users that this capability does not store historical data and is only a real-time indicator of location. Finally, it only generates a signal when you connect to a corporate network, which means that if you are working from home and connect your PC to your personal Wi-Fi, it won't broadcast your location to your employer; you will simply be shown as "Remote". Microsoft has encouraged IT admins to prepare for this change and begin informing users so they know what to expect once it begins rolling out later this year.
    • Wow, Microsoft IS cooking lately... This only shows that they COULD improve, they just chose not to for whatever reasons. That obsession with AI was destroying them from the inside out.
    • BATorrent 4.1.0 by Razvan Serea BATorrent is a lightweight, open-source BitTorrent client built with modern C++ and Qt 6, offering a clean, fast, and privacy-focused alternative to traditional torrent apps. It supports magnet links, .torrent files, resume data, sequential downloading, per-file priorities, and even imports from qBittorrent. Power users benefit from integrated RSS auto-download with regex filtering, duplicate detection, and automatic tracker lists from Stremio. Streaming is seamless thanks to auto-detected players like VLC and IINA. BATorrent includes robust VPN tools—interface binding, auto-detection for WireGuard-based services like Mullvad and NordLynx, kill switch, proxy support, and IP filtering. A full WebUI enables remote control, while integrations with Plex, Jellyfin, and Emby automate library updates. With themes, speed scheduling, system-tray alerts, and cross-platform support for Windows, Linux, and macOS, BATorrent delivers a polished, high-performance torrenting experience. BATorrent features: Core .torrent file and magnet link support Resume data — picks up where you left off after restart Import torrents from qBittorrent Create .torrent files from any file or folder Sequential download mode Per-file priority control (skip, low, normal, high) Seed ratio limits with auto-pause DHT, PEX, UPnP, NAT-PMP RSS Auto-Download Subscribe to RSS feeds — automatically download new torrents as they appear Regex filters — match only what you want (e.g. 1080p|720p, S01E\d+) Per-feed settings — custom save path, check interval (5–1440 min), enable/disable Auto-download — matched items are downloaded automatically in the background Supports magnet links, .torrent URLs, and tags Tray notifications when items are auto-downloaded Duplicate detection — never downloads the same item twice Stremio Stremio Addon System pre-installed — works out of the box Auto tracker list from ngosang/trackerslist Streaming Play while downloading — stream video files before the download is complete Supports mp4, mkv, avi, mov, wmv, flv, webm, m4v, ts Auto-detects installed players (VLC, IINA, system default) VPN & Privacy Interface binding — lock torrent traffic to a specific network interface (e.g. tun0) Auto VPN detection — identifies VPN interfaces (tun, tap, WireGuard, Mullvad, NordLynx, ProtonVPN) Kill switch — automatically pauses all torrents if the VPN interface drops Auto-resume — resumes only the torrents paused by the kill switch when VPN reconnects Proxy support — SOCKS5 and HTTP proxy with optional authentication IP filtering — load P2P blocklists to block unwanted IP ranges Protocol encryption (enabled / forced / disabled) WebUI Remote management — control torrents from any browser at http://localhost:8080 REST API with JSON responses Add torrents via magnet link or .torrent upload Pause, resume, remove torrents remotely View peers and files per torrent Dark theme matching the desktop app HTTP Basic Auth with SHA-256 password hashing Configurable port and remote access (localhost vs 0.0.0.0) Interface 3 themes: Dark, Light, Midnight (bat/vampire aesthetic) Real-time speed graph Detailed panel with tabs: General, Peers, Files, Trackers Filter bar: search by name, filter by state (Active, Downloading, Seeding, Paused, Finished) Drag & drop .torrent files and magnet links Drag & drop reorder in torrent list System tray with notifications (download complete, kill switch events, RSS auto-downloads) Splash screen with bat animation Bilingual: English and Portuguese (BR), auto-detected from system locale Bandwidth Scheduler Alternative speed limits — set different download/upload limits on a schedule Time range — configure active hours (e.g. 01:00 to 07:00), supports overnight ranges Per-day control — choose which days of the week the schedule applies Automatically switches between normal and alternative speeds Media Server Integration Plex — automatically trigger library scan when a download completes Jellyfin / Emby — same automatic library refresh via API Configure server URL and authentication token/key in Settings System Cross-platform: Windows, Linux, macOS Auto-shutdown — automatically shut down PC when all downloads complete (60s cancellable countdown) Auto-update system (AppImage on Linux, installer on Windows, DMG on macOS) CLI arguments: pass .torrent files or magnet: URIs directly Keyboard shortcuts: Space to toggle pause, Ctrl+A to select all, Ctrl+O to open BATorrent 4.1.0 release notes: A community-driven release: everything here came straight from your reports and requests. It closes the remaining gaps with qBittorrent and fixes the Windows settings/tray/splash issues several of you hit. Fixed Settings now actually save. A whole class of preferences — speed limits (and the alternative limits), max active downloads, seed ratio, listen port, max connections, DHT/uTP/encryption, VPN interface, kill switch and proxy — weren't being persisted and reset to defaults on every launch. They now round-trip correctly. (Thanks to everyone who reported "the upload limit always goes back to 0".) Splash and tray toggles stick on Windows. Turning off the startup animation (or "close to tray") no longer reverts — the Windows registry stored these booleans as integers and the UI was misreading them. Close-to-tray hint. The first time the window hides to the tray you get a one-time notification, so the app doesn't look like it vanished (Windows 11 tucks new tray icons into the overflow). macOS Dock icon size. The icon filled its canvas edge-to-edge and rendered larger than neighbouring apps; it now uses the standard safe-area padding. Native file picker language. The "Torrent file / All files" filter in the open dialog follows the app language instead of being hard-coded. Added — qBittorrent parity Alternative speed limits toggle — a turtle button in the toolbar flips your throttled limits on/off instantly, independent of the scheduler. Follow system theme — switch light/dark automatically with the OS (Settings → Appearance). Pre-allocate disk space — reserve the full file size up front to reduce fragmentation (Settings → Downloads). Recheck data on add — optionally force a hash check when adding a torrent, so existing or partial files on disk are detected. Port status indicator — a 🔴 dot in the status bar shows whether your listen port looks reachable (UPnP/NAT-PMP + listen state; fully local, no external check). Add torrent from URL — File → Add torrent from URL (Ctrl+U) fetches a remote .torrent and routes it through the normal add dialog. Export .torrent — right-click a torrent → Export .torrent to save its metadata file. Already there (in case you missed it) Watch folder — auto-add .torrent files dropped into a monitored directory (Settings → Files). This release just surfaces it. Incomplete files already carry a .!bt suffix until they finish. Under the hood Regression tests for the settings-persistence and Windows boolean bugs. A new Qt Quick Test harness covering the startup splash and the design-system widgets. Download: BATorrent 4.1.0 | 37.5 MB (Open Source) Download: BATorrent Portable | 51.7 MB Links: BATorrent Website | Screenshot | Changelog Get alerted to all of our Software updates on Twitter at @NeowinSoftware
  • Recent Achievements

    • Very Popular
      AndrewSteel earned a badge
      Very Popular
    • Veteran
      Taliseian went up a rank
      Veteran
    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
  • Popular Contributors

    1. 1
      +primortal
      511
    2. 2
      +Edouard
      162
    3. 3
      PsYcHoKiLLa
      157
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      80
  • Tell a friend

    Love Neowin? Tell a friend!