问:
How to interact with Cookie pop within #shadow-root (open) using Selenium
I would like to scrap immowelt.de, but I could not get pass the cookie banner.
I tried to wait for the banner to load using both sleep() and WebDriverWait, however none of them is working.

This is the code with the webdriver

```<code>from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

chrome_driver_path = '.../chromedriver'
url = 'https://www.immowelt.de/immobilienpreise'
driver = webdriver.Chrome(executable_path=chrome_driver_path)

driver.get(url)

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="uc-center-container"]/div[2]/div/div/div/div[1]/button'))).click()

driver.close()
</code>```

And this is the code with sleep

```<code>from selenium import webdriver
import time
from selenium.webdriver.common.by import By

chrome_driver_path = '.../chromedriver'
url = 'https://www.immowelt.de/immobilienpreise'
driver = webdriver.Chrome(executable_path=chrome_driver_path)

driver.get(url)
time.sleep(5)
driver.find_element(By.XPATH, '//*[@id="uc-center-container"]/div[2]/div/div/div/div[1]/button').click()

driver.close()
</code>```

答:
The element OK is within #shadow-root (open).

Solution

To click on OK you have to use shadowRoot.querySelector() and you can use the following Locator Strategy:

Code Block:

```<code>driver.get("https://www.immowelt.de/immobilienpreise")
time.sleep(5)
element = driver.execute_script("""return document.querySelector('#usercentrics-root').shadowRoot.querySelector("button[data-testid='uc-accept-all-button']")""")
element.click()
</code>```

References

You can find a couple of relevant discussions in:

How to handle the popup "Accepting all cookies" when the element is data-testid - Using Selenium in Python

Can't locate elments within shadow-root (open) using Python Selenium

How to get past a cookie agreement page using Python and Selenium?

Body:
I would like to scrap immowelt.de, but I could not get pass the cookie banner.
I tried to wait for the banner to load using both sleep() and WebDriverWait, however none of them is working.

This is the code with the webdriver

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

chrome_driver_path = '.../chromedriver'
url = 'https://www.immowelt.de/immobilienpreise'
driver = webdriver.Chrome(executable_path=chrome_driver_path)

driver.get(url)

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="uc-center-container"]/div[2]/div/div/div/div[1]/button'))).click()

driver.close()

And this is the code with sleep

from selenium import webdriver
import time
from selenium.webdriver.common.by import By

chrome_driver_path = '.../chromedriver'
url = 'https://www.immowelt.de/immobilienpreise'
driver = webdriver.Chrome(executable_path=chrome_driver_path)

driver.get(url)
time.sleep(5)
driver.find_element(By.XPATH, '//*[@id="uc-center-container"]/div[2]/div/div/div/div[1]/button').click()

driver.close()

Body:
The element OK is within #shadow-root (open).

Solution

To click on OK you have to use shadowRoot.querySelector() and you can use the following Locator Strategy:

Code Block:

driver.get("https://www.immowelt.de/immobilienpreise")
time.sleep(5)
element = driver.execute_script("""return document.querySelector('#usercentrics-root').shadowRoot.querySelector("button[data-testid='uc-accept-all-button']")""")
element.click()

References

You can find a couple of relevant discussions in:

How to handle the popup "Accepting all cookies" when the element is data-testid - Using Selenium in Python

Can't locate elments within shadow-root (open) using Python Selenium

How to get past a cookie agreement page using Python and Selenium?


来源: stackexchange

问:
Virtual functions in class instantiated with std::tuple<void>
I am working on a class that accepts a tuple of types of messages this obect will receive. In our model, we're using void to express the existence of a message that does not carry data, just a signal. The tuple is never actually instantiated but we inspect its types and generate various callbacks based on them. I have seen several references that suggest the use of std::tuple as replacement for variadic templates and the use of void in std::tuple (e.g., Void type in std::tuple).

All seems to work well, until I introduce a virtual member function that calls an external function:

```<code>#include <tuple>

void foo(void *);

template <typename TupleT>
class TT {
public:
    TT(){}

    void bar() {
    }

    void work() {
      bar();       // OK
      foo(this);   // UPDATE: NOT OK
    }

    virtual void fail() {
      bar();       // OK
      foo(this);   // NOT OK
    }
};

TT<std::tuple<void>> tt;
</code>```

The compiler error I get tells me that the std::tuple<void> is actually instantiated in the virtual member function:

```<code>In file included from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::_Head_base<0, void, false>':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:407:12:   required from 'struct std::_Tuple_impl<0, void>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:599:11:   required from 'class std::tuple<void>'
<source>:26:10:   required from 'void TT<TupleT>::fail() [with TupleT = std::tuple<void>]'
<source>:25:18:   required from here
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:182:17: error: forming reference to void
  182 |       constexpr _Head_base(const _Head& __h)
      |                 ^~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:219:7: error: forming reference to void
  219 |       _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
      |       ^~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:222:7: error: forming reference to void
  222 |       _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
      |       ^~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:224:13: error: 'std::_Head_base<_Idx, _Head, false>::_M_head_impl' has incomplete type
  224 |       _Head _M_head_impl;
      |             ^~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:224:13: error: invalid use of 'void'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::_Tuple_impl<0, void>':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:599:11:   required from 'class std::tuple<void>'
<source>:26:10:   required from 'void TT<TupleT>::fail() [with TupleT = std::tuple<void>]'
<source>:25:18:   required from here
</code>```

Can someone explain to me why the compile attempts to instantiate the tuple in a virtual member function?

The obvious workaround seems to be to call a non-virtual member function and move the external call into it (calling works() from fail() in the example instead of calling foo() directly). While this works, it is rather unsatisfactory and I'd like to understand what happens here.

UPDATE: As pointed out in the comments, a call to work() causes the same problem (I thought I had tested it but compiled the wrong file...). I'd still like to understand why passing a pointer to TT has the compiler instantiate the tuple...?

Thanks for any hints :)

答: This is ADL causing trouble again: the std::tuple specialization is an associated entity via your template argument, and so it must be checked for friend declarations when (a pointer to) a TT is an argument.

ContentLicense: CC BY-SA 4.0

Body:
I am working on a class that accepts a tuple of types of messages this obect will receive. In our model, we're using void to express the existence of a message that does not carry data, just a signal. The tuple is never actually instantiated but we inspect its types and generate various callbacks based on them. I have seen several references that suggest the use of std::tuple as replacement for variadic templates and the use of void in std::tuple (e.g., Void type in std::tuple).

All seems to work well, until I introduce a virtual member function that calls an external function:

#include <tuple>

void foo(void *);

template <typename TupleT>
class TT {
public:
    TT(){}

    void bar() {
    }

    void work() {
      bar();       // OK
      foo(this);   // UPDATE: NOT OK
    }

    virtual void fail() {
      bar();       // OK
      foo(this);   // NOT OK
    }
};

TT<std::tuple<void>> tt;

The compiler error I get tells me that the std::tuple<void> is actually instantiated in the virtual member function:

In file included from <source>:1:
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::_Head_base<0, void, false>':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:407:12:   required from 'struct std::_Tuple_impl<0, void>'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:599:11:   required from 'class std::tuple<void>'
<source>:26:10:   required from 'void TT<TupleT>::fail() [with TupleT = std::tuple<void>]'
<source>:25:18:   required from here
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:182:17: error: forming reference to void
  182 |       constexpr _Head_base(const _Head& __h)
      |                 ^~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:219:7: error: forming reference to void
  219 |       _M_head(_Head_base& __b) noexcept { return __b._M_head_impl; }
      |       ^~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:222:7: error: forming reference to void
  222 |       _M_head(const _Head_base& __b) noexcept { return __b._M_head_impl; }
      |       ^~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:224:13: error: 'std::_Head_base<_Idx, _Head, false>::_M_head_impl' has incomplete type
  224 |       _Head _M_head_impl;
      |             ^~~~~~~~~~~~
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:224:13: error: invalid use of 'void'
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple: In instantiation of 'struct std::_Tuple_impl<0, void>':
/opt/compiler-explorer/gcc-11.2.0/include/c++/11.2.0/tuple:599:11:   required from 'class std::tuple<void>'
<source>:26:10:   required from 'void TT<TupleT>::fail() [with TupleT = std::tuple<void>]'
<source>:25:18:   required from here

Can someone explain to me why the compile attempts to instantiate the tuple in a virtual member function?

The obvious workaround seems to be to call a non-virtual member function and move the external call into it (calling works() from fail() in the example instead of calling foo() directly). While this works, it is rather unsatisfactory and I'd like to understand what happens here.

UPDATE: As pointed out in the comments, a call to work() causes the same problem (I thought I had tested it but compiled the wrong file...). I'd still like to understand why passing a pointer to TT has the compiler instantiate the tuple...?

Thanks for any hints :)


问:
Conditional Rendering not waiting for Fetch to Complete
In the App i fetch Data from Firebase/Firestore, parse it to a Interface and add the object to the State Array. After that i want to render it. But react wont render the array. I Have commented the Code that you can see what i thought it should do.

```<code>const Tab1: React.FC = () => {

  let spiceArray: singleSpice[] = [];

  interface singleSpice {
    spice: string,
    grams: number,
  }

  useEffect(() => {
    //fetch the data --> Works well
    async function loadData() {
      const data = await getCollections();
    // Add the Data to the Spicearray --> Works
      data.forEach((e: any) => spiceArray.push(e));
    }
    // Trigger Function onComponentMount
    loadData();
    // This function will never log "Worked" even tho the loadData is Async
    if(spiceArray.length > 0){
      console.log("Worked")
    }

  })

  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Tab 1</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent fullscreen>
        <IonHeader collapse="condense">
          <IonToolbar>
            <IonTitle size="large">Tab 1</IonTitle>
          </IonToolbar>
        </IonHeader>
        //Transfer the spiceArray to the next Child as Props --> Works
        <CustomTab1 spices={spiceArray}/>
        <ExploreContainer name="Tab 1 page" />
        <IonButton onClick={() => console.log(spiceArray.length)}> Test me</IonButton>

      </IonContent>
    </IonPage>
  );
};

export default Tab1;
</code>```

Child

```<code>    //Interface for Props
    interface Props {
        spices: Spice[];
    }
    //Interface to get access to inner Attributes of the SpiceObjectArray
    interface Spice {
        spice: string;
        grams: number;
    }

    const CustomTab1: React.FC<Props> = ({spices}: Props) => {
        return (
        <IonList>
            //Conditional Render
            {spices.length > 0 && spices.map(entry => <IonItem id={entry.spice}>{entry.spice}</IonItem>)}
            <IonButton onClick={() => console.log(spices)}>Test</IonButton>
        </IonList>

        );
      };

      export default CustomTab1;
</code>```

Crazy Thing is. Right now when i F5 the IonicApp none of the spices is Displayed. But when i change the text inside the IoNButton on CustomTab1-Component and save the simple change the spices getting rendered. But if i press F5 to refresh the app everything is gone again.How can i make the app wait until the API delivers the data?

答:
spiceArray is not a state and can't rerender your child component.

change your variable to state

Body:
In the App i fetch Data from Firebase/Firestore, parse it to a Interface and add the object to the State Array. After that i want to render it. But react wont render the array. I Have commented the Code that you can see what i thought it should do.

const Tab1: React.FC = () => {

  let spiceArray: singleSpice[] = [];

  interface singleSpice {
    spice: string,
    grams: number,
  }

  useEffect(() => {
    //fetch the data --> Works well
    async function loadData() {
      const data = await getCollections();
    // Add the Data to the Spicearray --> Works
      data.forEach((e: any) => spiceArray.push(e));
    }
    // Trigger Function onComponentMount
    loadData();
    // This function will never log "Worked" even tho the loadData is Async
    if(spiceArray.length > 0){
      console.log("Worked")
    }

  })

  return (
    <IonPage>
      <IonHeader>
        <IonToolbar>
          <IonTitle>Tab 1</IonTitle>
        </IonToolbar>
      </IonHeader>
      <IonContent fullscreen>
        <IonHeader collapse="condense">
          <IonToolbar>
            <IonTitle size="large">Tab 1</IonTitle>
          </IonToolbar>
        </IonHeader>
        //Transfer the spiceArray to the next Child as Props --> Works
        <CustomTab1 spices={spiceArray}/>
        <ExploreContainer name="Tab 1 page" />
        <IonButton onClick={() => console.log(spiceArray.length)}> Test me</IonButton>

      </IonContent>
    </IonPage>
  );
};

export default Tab1;

Child

    //Interface for Props
    interface Props {
        spices: Spice[];
    }
    //Interface to get access to inner Attributes of the SpiceObjectArray
    interface Spice {
        spice: string;
        grams: number;
    }

    const CustomTab1: React.FC<Props> = ({spices}: Props) => {
        return (
        <IonList>
            //Conditional Render
            {spices.length > 0 && spices.map(entry => <IonItem id={entry.spice}>{entry.spice}</IonItem>)}
            <IonButton onClick={() => console.log(spices)}>Test</IonButton>
        </IonList>

        );
      };

      export default CustomTab1;

Crazy Thing is. Right now when i F5 the IonicApp none of the spices is Displayed. But when i change the text inside the IoNButton on CustomTab1-Component and save the simple change the spices getting rendered. But if i press F5 to refresh the app everything is gone again.How can i make the app wait until the API delivers the data?


问:
Why can't I echo into a regex-matched output file
I have a file that looks like this:

filename.txt

```<code>first line
prefix=C:\Users\me\tmp\out_file.txt
second line
python args
</code>```

What I'm trying to do is run the python script and then echo the output into the file C:\Users\me\tmp\out_file.txt. Running the script is very easy, but echoing the output is proving difficult. filename.txt is in C:\Users\me\tmp, so I open a powershell terminal there and execute the following:

```<code>Get-ChildItem | Get-Content -Raw | Select-String -Pattern "(?smi)(?:prefix=([^\n]*?))$.*?(python .*?)$" | %{echo "hello" > $_.Matches.Groups[1].Value}
</code>```

What this is doing is matching the python script and the output file (note that in general I will be executing this script for every file, hence the pipes). But this results in the error:

```<code>Out-File: The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\me\tmp\out_file.txt'
</code>```

Now, If I copy and paste that exact filename:

```<code>echo "hello" > 'C:\Users\me\tmp\out_file.txt'
</code>```

The result works perfectly (it also works without the quotes). So my question is, why does this fail in the ForEach-Object loop?

In the end, I will call

```<code>ForEach-Object -Parallel {Invoke-Expression $_.Matches.Groups[2].Value > $_.Matches.Groups[1].Value}
</code>```

Which (hopefully) will pipe the output into the output file, but if there is a better way of achieving this that would be helpful as well.

答:
The issue is that you are capturing the CR (Carriage Return) character at the end of the line. If you look at $_.Matches.Groups[1] you'll see:

```<code>Success  : True
Name     : 1
Captures : {1}
Index    : 19
Length   : 29
Value    : C:\Users\me\tmp\out_file.txt
</code>```

Note the length of 29, but the file path is only 28 characters. If you do:

```<code>Get-ChildItem | Get-Content -Raw | Select-String -Pattern "(?smi)(?:prefix=([^\n]*?))$.*?(python .*?)$" | %{$_.Matches.Groups[1].Value.ToCharArray()|%{">$_<"}}
</code>```

You should see that the last few entries appear as:

```<code>>e<
>.<
>t<
>x<
>t<
><
</code>```

Indicating that there's an invisible character there. You can fix that by altering your regex just a little:

```<code>"(?smi)(?:prefix=(.*?))[\r\n]+.*?(python .*?)$"
</code>```

Body:
I have a file that looks like this:

filename.txt

first line
prefix=C:\Users\me\tmp\out_file.txt
second line
python args

What I'm trying to do is run the python script and then echo the output into the file C:\Users\me\tmp\out_file.txt. Running the script is very easy, but echoing the output is proving difficult. filename.txt is in C:\Users\me\tmp, so I open a powershell terminal there and execute the following:

Get-ChildItem | Get-Content -Raw | Select-String -Pattern "(?smi)(?:prefix=([^\n]*?))$.*?(python .*?)$" | %{echo "hello" > $_.Matches.Groups[1].Value}

What this is doing is matching the python script and the output file (note that in general I will be executing this script for every file, hence the pipes). But this results in the error:

Out-File: The filename, directory name, or volume label syntax is incorrect. : 'C:\Users\me\tmp\out_file.txt'

Now, If I copy and paste that exact filename:

echo "hello" > 'C:\Users\me\tmp\out_file.txt'

The result works perfectly (it also works without the quotes). So my question is, why does this fail in the ForEach-Object loop?

In the end, I will call

ForEach-Object -Parallel {Invoke-Expression $_.Matches.Groups[2].Value > $_.Matches.Groups[1].Value}

Which (hopefully) will pipe the output into the output file, but if there is a better way of achieving this that would be helpful as well.

Body:
The issue is that you are capturing the CR (Carriage Return) character at the end of the line. If you look at $_.Matches.Groups[1] you'll see:

Success  : True
Name     : 1
Captures : {1}
Index    : 19
Length   : 29
Value    : C:\Users\me\tmp\out_file.txt

Note the length of 29, but the file path is only 28 characters. If you do:

Get-ChildItem | Get-Content -Raw | Select-String -Pattern "(?smi)(?:prefix=([^\n]*?))$.*?(python .*?)$" | %{$_.Matches.Groups[1].Value.ToCharArray()|%{">$_<"}}

You should see that the last few entries appear as:

>e<
>.<
>t<
>x<
>t<
><

Indicating that there's an invisible character there. You can fix that by altering your regex just a little:

"(?smi)(?:prefix=(.*?))[\r\n]+.*?(python .*?)$"


问:
Groupby A column and bring up the A value, only if the B values differ from the other ones, including nulls
I have this example, dataset:

```<code> A   B
11   A
11   V
11   C
12   A
12   A
12   A
12   A
13   A
13   A
13   B
13   B
14   C
14   C
14
14
</code>```

And I want it to return, the grouped A values, that has different values on the B column. So in this example, the expected output is:

```<code>[11, 13,14]
</code>```

I made an attempt at formulating the code, and I succeeded but it is terrible and  unoptimized. And I was looking for alternatives so I could iterate faster through my much bigger dataset. Would appreciate some help.

Here is my code:

```<code>user_mult_camps = []

for i in  df['A'].unique():
    filt = (df['A'] == i)
    df2 = df.loc[filt]
    x=df2['B'].unique()
    if len(x) > 1:
        user_mult_camps.append(i)
        print(i)
</code>```

答:
Try this:

```<code>out = df.groupby('A')['B'].nunique().pipe(lambda x: x[x > 1].index.to_numpy())
</code>```

Output:

```<code>>>> out
array([11])

>>> out[0]
11
</code>```

Body:
I have this example, dataset:

 A   B
11   A
11   V
11   C
12   A
12   A
12   A
12   A
13   A
13   A
13   B
13   B
14   C
14   C
14
14

And I want it to return, the grouped A values, that has different values on the B column. So in this example, the expected output is:

[11, 13,14]

I made an attempt at formulating the code, and I succeeded but it is terrible and  unoptimized. And I was looking for alternatives so I could iterate faster through my much bigger dataset. Would appreciate some help.

Here is my code:

user_mult_camps = []

for i in  df['A'].unique():
    filt = (df['A'] == i)
    df2 = df.loc[filt]
    x=df2['B'].unique()
    if len(x) > 1:
        user_mult_camps.append(i)
        print(i)

Body:
Try this:

out = df.groupby('A')['B'].nunique().pipe(lambda x: x[x > 1].index.to_numpy())

Output:

>>> out
array([11])

>>> out[0]
11


答:
React doesn't rerender when variables change. You say you are passing the fetched object to the "state array" but spiceArray is not a piece of react state. In a functional component, state is declared with useState.

When your page initially loads, there is no data, and you have the right idea to check if there is first any data before trying to map over/render it. But in order to get the component to rerender and thus recheck if spicesArray has anything in it you must use state and make a change to state.

```<code>const [spiceArray, setSpiceArray] = useState<singleSpice[] | null>(null)
  useEffect(() => {
    //fetch the data --> Works well
    async function loadData() {
      const data = await getCollections();
    // Add the Data to the Spicearray --> Works
     setSpiceArray(data)
    }
    // Trigger Function onComponentMount
    loadData();

    // This function will never log "Worked" even tho the loadData is Async
    if (spiceArray.length > 0) {
      console.log("Worked");
    }
  }, []);
</code>```

your code should look something like this
and change child component rendering logic to:

```<code>{spices && spices.map(entry => <IonItem id={entry.spice}>{entry.spice}</IonItem>)}
</code>```

Keep in mind a couple of other things:

if you want useEffect to run only on mount (which is usually the case when fetching data), you need an empty dependency array.

console logging the spiceArray or checking if the spiceArray.length is not 0 will still not work in useEffect because state updates in react are async/ a request to update state for the next render. Therefor, changes will not be immediately reflected/ observable

Title: Conditional Rendering not waiting for Fetch to Complete

Body:
React doesn't rerender when variables change. You say you are passing the fetched object to the "state array" but spiceArray is not a piece of react state. In a functional component, state is declared with useState.

When your page initially loads, there is no data, and you have the right idea to check if there is first any data before trying to map over/render it. But in order to get the component to rerender and thus recheck if spicesArray has anything in it you must use state and make a change to state.

const [spiceArray, setSpiceArray] = useState<singleSpice[] | null>(null)
  useEffect(() => {
    //fetch the data --> Works well
    async function loadData() {
      const data = await getCollections();
    // Add the Data to the Spicearray --> Works
     setSpiceArray(data)
    }
    // Trigger Function onComponentMount
    loadData();

    // This function will never log "Worked" even tho the loadData is Async
    if (spiceArray.length > 0) {
      console.log("Worked");
    }
  }, []);

your code should look something like this
and change child component rendering logic to:

{spices && spices.map(entry => <IonItem id={entry.spice}>{entry.spice}</IonItem>)}

Keep in mind a couple of other things:

if you want useEffect to run only on mount (which is usually the case when fetching data), you need an empty dependency array.

console logging the spiceArray or checking if the spiceArray.length is not 0 will still not work in useEffect because state updates in react are async/ a request to update state for the next render. Therefor, changes will not be immediately reflected/ observable


问:
Execute script or process right before kernel kills app with OOM
Is there a way to run a script right before a process is killed for OOM?

My go process is slowly accumulating memory and eventually the kernel kills it because the host is going out of memory.

The process exposes pprof metrics over an http socket, and the script I want to run would curl to that socket and save the pprof memory information.

That way I have a base for debugging why the process goes out of memory, as recommended in this GitHub post.

More info:

The error:

```<code>Out of memory: Killed process 9421 (process_name) total-vm:10185280kB, anon-rss:6358304kB, file-rss:0kB, shmem-rss:0kB, UID:994 pgtables:12884kB oom_score_adj:0
</code>```

I know the kill signal is kernel-only, so my process cannot subscribe to that, but is there another signal I should be looking into? Or might the best course of action be to poll the localhost pprof URL at regular time intervals?

Thanks!

答:
Is there a way to run a script right before a process is killed for OOM?

No.

Body:
Is there a way to run a script right before a process is killed for OOM?

My go process is slowly accumulating memory and eventually the kernel kills it because the host is going out of memory.

The process exposes pprof metrics over an http socket, and the script I want to run would curl to that socket and save the pprof memory information.

That way I have a base for debugging why the process goes out of memory, as recommended in this GitHub post.

More info:

The error:

Out of memory: Killed process 9421 (process_name) total-vm:10185280kB, anon-rss:6358304kB, file-rss:0kB, shmem-rss:0kB, UID:994 pgtables:12884kB oom_score_adj:0

I know the kill signal is kernel-only, so my process cannot subscribe to that, but is there another signal I should be looking into? Or might the best course of action be to poll the localhost pprof URL at regular time intervals?

Thanks!


问:
How to match a value in one column to another column based on hierarchy level
I have a table that contains 4 columns: entry_id, NAME, type, upper_id.

Each entry_id corresponds to a specific upper_id. There can be many different entry_id's that correspond to SAME upper_id. The column type represent the level of that entry in terms of hierarchy.

```<code>1 --> First level
2 --> Second level
3 --> Third level
</code>```

I need to match what is in the upper_id to the entry_id in order to add another column for upper_name which will be found in the same table column name. In the example above, if upper_id = '1001' for an entry_id, I need to find this value in the entry_id and grab the name found.

An entry_id with type = '1' will always have an upper_id that has a value in the entry_id with a type = '2'. And an entry_id with a type = '2' will always have an upper id that has a value in entry_id with a type = '3'. An entry_id with type = '3' will never have an upper_id, and its upper_name column will be NULL.

The results will  look like this:

```<code>CREATE TABLE TBL_1
(     ENTRY_ID int,
      NAME string,
      TYPE int,
      UPPER_ID int
);

INSERT INTO TBL_1
values
(1234,'bichon',1,'1001'),
(1124,'yorkie',1,'1001'),
(1009,'golden',1,'1001'),
(6722,'poodle',1,'1001'),
(1001,'canine',2,'2002'),
(2002,'animal',3,NULL)
</code>```

Do you know how I can formulate a query that allows me to include an "upper_name" column from the data already in the table?

答:
Join the table to itself on upper_id = entry_id and type = type - 1, then union all with the type 3 rows.</p>
```<code>SELECT x.*, y.NAME as upper_name
FROM tbl_1 x
    inner join tbl_1 y on x.UPPER_ID = y.ENTRY_ID and x.TYPE = y.TYPE - 1
WHERE x.TYPE IN (1,2)
UNION ALL
SELECT *, NULL AS upper_name
FROM TBL_1
WHERE type = 3;
</code>```

Body:
I have a table that contains 4 columns: entry_id, NAME, type, upper_id.

Each entry_id corresponds to a specific upper_id. There can be many different entry_id's that correspond to SAME upper_id. The column type represent the level of that entry in terms of hierarchy.

1 --> First level
2 --> Second level
3 --> Third level

I need to match what is in the upper_id to the entry_id in order to add another column for upper_name which will be found in the same table column name. In the example above, if upper_id = '1001' for an entry_id, I need to find this value in the entry_id and grab the name found.

An entry_id with type = '1' will always have an upper_id that has a value in the entry_id with a type = '2'. And an entry_id with a type = '2' will always have an upper id that has a value in entry_id with a type = '3'. An entry_id with type = '3' will never have an upper_id, and its upper_name column will be NULL.

The results will  look like this:

CREATE TABLE TBL_1
(     ENTRY_ID int,
      NAME string,
      TYPE int,
      UPPER_ID int
);

INSERT INTO TBL_1
values
(1234,'bichon',1,'1001'),
(1124,'yorkie',1,'1001'),
(1009,'golden',1,'1001'),
(6722,'poodle',1,'1001'),
(1001,'canine',2,'2002'),
(2002,'animal',3,NULL)

Do you know how I can formulate a query that allows me to include an "upper_name" column from the data already in the table?

Body:
Join the table to itself on upper_id = entry_id and type = type - 1, then union all with the type 3 rows.

SELECT x.*, y.NAME as upper_name
FROM tbl_1 x
    inner join tbl_1 y on x.UPPER_ID = y.ENTRY_ID and x.TYPE = y.TYPE - 1
WHERE x.TYPE IN (1,2)
UNION ALL
SELECT *, NULL AS upper_name
FROM TBL_1
WHERE type = 3;


问:
Remove keys from object that are not in an array
I'm looking for an elegant way to do the following:

I have a JS object:

```<code>     var sObject = {};
     sObject[Col1] = "Value1";
     sObject[Col2] = "Value2";
     sObject[Col2] = "Value3";
</code>```

I also have an array

```<code>     var arrayCols=[];
     arrayCols.push("Col2");
</code>```

What I am trying to do is remove all the key/values from sObject where Key != arrayCols key

Once the needful is done, my sObject should only contain  Col2:Value2 as Col2 is the only key in the arrayCols

I'm trying something along the lines of:

var sObject = {};
sObject['Col1'] = "Value1";
sObject['Col2'] = "Value2";
sObject['Col2'] = "Value3";

var arrayCols = [];
arrayCols.push("Col2");

let newObject = {};

for (const [key, value] of Object.entries(sObject)) {
  if (key in arrayCols) {
    newObject[key] = value;
  }
}

console.log(newObject);```

答:
E. g. using reduce:

var sObject = {};
sObject.Col1 = "Value1";
sObject.Col2 = "Value2";
sObject.Col2 = "Value3";

var arrayCols = [];
arrayCols.push("Col2");

sObject = arrayCols.reduce((a, k) => (a[k] = sObject[k], a), {})

console.log(sObject)```

Body:
I'm looking for an elegant way to do the following:

I have a JS object:

     var sObject = {};
     sObject[Col1] = "Value1";
     sObject[Col2] = "Value2";
     sObject[Col2] = "Value3";

I also have an array

     var arrayCols=[];
     arrayCols.push("Col2");

What I am trying to do is remove all the key/values from sObject where Key != arrayCols key

Once the needful is done, my sObject should only contain  Col2:Value2 as Col2 is the only key in the arrayCols

I'm trying something along the lines of:

var sObject = {};
sObject['Col1'] = "Value1";
sObject['Col2'] = "Value2";
sObject['Col2'] = "Value3";

var arrayCols = [];
arrayCols.push("Col2");

let newObject = {};

for (const [key, value] of Object.entries(sObject)) {
  if (key in arrayCols) {
    newObject[key] = value;
  }
}

console.log(newObject);


问:
How can I fix this error: Uncaught SyntaxError: expected expression, got '<'?
I want to get the data from the JSON file, it works fine on my computer, but when I put it on my server, it shows this error.

Error: Uncaught SyntaxError: expected expression, got '<'

This is my code:

setInterval(function () {
    loadJSON(function (response) {
        jsonresponse = JSON.parse(response);
        document.getElementById('stats').innerHTML = jsonresponse[0].name;
    });
}, 1000);

function loadJSON(callback) {
    var xobj = new XMLHttpRequest();
    xobj.overrideMimeType('application/json');
    xobj.open('GET', 'data.json', true);
    xobj.onreadystatechange = function () {
        if (xobj.readyState == 4 && xobj.status == '200') {
            callback(xobj.responseText);
        }
    }
    xobj.send(null);
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="/style.css">
    </head>
    <script src="./index.js"></script>
    <script src="./node.js"></script>
    <script src="./data.json"></script>
    </body>
</html></code>```

Any idea of how to fix this?

答:
Well I fixed it by just deleting and recreating the file.
Thanks for your help I appreciate it!</p>

Body:
I want to get the data from the JSON file, it works fine on my computer, but when I put it on my server, it shows this error.

Error: Uncaught SyntaxError: expected expression, got '<'

This is my code:

setInterval(function () {
    loadJSON(function (response) {
        jsonresponse = JSON.parse(response);
        document.getElementById('stats').innerHTML = jsonresponse[0].name;
    });
}, 1000);

function loadJSON(callback) {
    var xobj = new XMLHttpRequest();
    xobj.overrideMimeType('application/json');
    xobj.open('GET', 'data.json', true);
    xobj.onreadystatechange = function () {
        if (xobj.readyState == 4 && xobj.status == '200') {
            callback(xobj.responseText);
        }
    }
    xobj.send(null);
}

<!DOCTYPE html>

        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="/style.css">

Any idea of how to fix this?


答:
Do you not have to await loadData();?

Then move on to if(spiceArray.length > 0){


答:
See [temp.inst]/4:

Unless a member of a templated class is a declared specialization, the specialization of the member is implicitly instantiated when the specialization is referenced in a context that requires the member definition to exist ...

Thus, a member function of TT<std::tuple<void>> will only be instantiated once you do something that requires it to have a definition, and not before.

As long as you don't call TT<std::tuple<void>>::work, take its address, or otherwise odr-use it, it's not required to have a definition.

However, TT<std::tuple<void>>::fail is different because it is virtual. According to [basic.def.odr]/7, a virtual function is always considered to be odr-used (which forces its definition to exist) unless it is pure. That implies that as soon as the enclosing class is instantiated, which brings the virtual function into existence, the definition of that function must also be instantiated. Informally, the reason for this is that the implementation must generate the definition so that it can set up the vtable for the class.

So far, we've established that your program necessarily instantiates TT<std::tuple<void>>::fail. If you call work, that function is also instantiated. In either case, the expression foo(this) is then instantiated and a compilation error occurs. The remaining question is why foo(this) tries to instantiate std::tuple<void>?

The answer is that this is an unqualified function call and is subject to argument-dependent lookup. To perform this lookup, the compiler must determine the associated entities of decltype(this). This will "look through" pointers and recursively descend into type template arguments and base classes. So the compiler ends up determining that it must know the set of base classes of std::tuple<void> in order to complete the argument-dependent lookup. But the base classes of a class are specified as part of its definition, so the compiler has no choice but to instantiate std::tuple<void>.

You may suppress argument-dependent lookup by calling ::foo(this). In that case, your code will compile.

One possible way to avoid these issues entirely is to use std::tuple<std::type_identity<void>> instead (note the absence of _t). std::type_identity<T> is an empty struct for all T and is well-behaved as an element of a std::tuple.

Title: Virtual functions in class instantiated with std::tuple<void>


答:
You can use Object.fromEntries and map:

var obj = { Col1: "Value1",  Col2: "Value2",  Col3: "Value3" };
var cols = ["Col2"];

var result = Object.fromEntries(cols.map(col => [col, obj[col]]));

console.log(result);```

Title: Remove keys from object that are not in an array


问:
LNK2019: unresolved external symbol - linking .h files with .cpp (definition) files in Visual Studio 2022 isn't working
Okay, so I'm currently a beginner programmer for C++ (year 11 in school, 3rd year of high school but we're still studying basic functions, so please excuse any rookie mistakes) and I'm learning additional coding knowledge by myself. Context aside, I moved to Visual Studio 2022 and I'm following a course, currently learning about Inheritance.

Thing is, I have a project with a base Account class and 3 other publicly derived classes (from the Account class) and each of these have headers and definition files, but whenever I try to run the main I get the following error chain:

```<code>1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > const &,double)" (?deposit@@YAXAEBV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > const &,double)" (?withdraw@@YAXAEBV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>C:\Users\Sapok\Desktop\Programming_projects\Visual Studio\ConstructorsAndDestructors\x64\Debug\3. Inheritance - DerivingClasses.exe : fatal error LNK1120: 8 unresolved externals
</code>```

From what I've gathered, the compiler is either pissed that it hasn't found any definitions for the functions I declared in the headers, or it's pissed that it can't tell apart between the "deposit" and "withdraw" functions for each class (each class has those 2 methods and they're named the same everywhere, but inheritance should make it work fine, I've checked the code itself and no other compiler errors appear). At this point, I'm genuinely stumped as to what the hell the compiler's crying about and how to fix it.

I've tried to include all the headers in all the files, all the .cpp files everywhere. Including the .cpp files only makes it spit out the LNK1169 (multiply defined symbols) instead, so no bueno. I've tried copying everything to a fresh solution and to no avail, I've double and triple checked all the code, I've tried moving files around, I've scoured a number of posts talking about this same type of error and none of them seem to help.

(A screenshot of my project's file distribution):
https://i.stack.imgur.com/gOXym.png

For example's sake, here's my base Account class header...

```<code>#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
#include <iostream>

class Account {
    friend std::ostream& operator<< (std::ostream &out, const Account& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
protected:
    std::string name;
    double balance;
public:
    Account(std::string name = def_name, double balance = def_balance);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _ACCOUNT_H_
</code>```

...and its definition .cpp file.

```<code>#include "Account.h"
#include <string>
#include <iostream>

Account::Account(std::string name, double balance)
    : name{ name }, balance{ balance } {}

bool Account::deposit(double amount) {
    if (amount < 0)
        return false;
    else {
        balance += amount;
        return true;
    }
}

bool Account::withdraw(double amount) {
    if (balance - amount < 0)
        return false;
    else {
        balance -= amount;
        return true;
    }
}

std::ostream& operator<<(std::ostream& out, const Account& account) {
    out << "[Account: " << account.name << ": " << account.balance << "]";
    return out;
}
</code>```

All the other classes are very similar, as inheritance usually works.

Sorry for the long-winded explanation, I'm still new to all this and I just wanna make sure I get all the necessary details across. If anyone has any general etiquette tips for help posts like this one, that'd be greatly appreciated as well :)

Thanks in advance!

Edit: I'll include all the code - I think this isn't clear enough.

Account.h and Account.cpp are included above

SavingsAccount.h:

```<code>#ifndef _SAVINGSACCOUNT_H_
#define _SAVINGSACCOUNT_H_
#include "Account.h"
#include <string>
#include <iostream>

class SavingsAccount : public Account{
    friend std::ostream& operator<< (std::ostream& out, const SavingsAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_interest = 0.0;
protected:
    double interest;
public:
    SavingsAccount(std::string name = def_name, double balance = def_balance, double interest = def_interest);
    bool deposit(double amount);
    // Inherited withdraw
};

#endif // _SAVINGSACCOUNT_H_
</code>```

SavingsAccount.cpp:

```<code>#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

SavingsAccount::SavingsAccount(std::string name, double balance, double interest)
    : Account(name, balance), interest{ interest } {}

bool SavingsAccount::deposit(double amount) {
    amount += amount * (interest / 100);
    return Account::deposit(amount);
}

std::ostream& operator<<(std::ostream& out, const SavingsAccount& account) {
    out << "[SavingsAccount: " << account.name << ": " << account.balance << ", " << account.interest << "%]";
    return out;
}
</code>```

CheckingAccount.h:

```<code>#ifndef _CHECKINGACCOUNT_H_
#define _CHECKINGACCOUNT_H_
#include "Account.h"
#include <string>
#include <iostream>

class CheckingAccount : public Account {
    friend std::ostream& operator<< (std::ostream& out, const CheckingAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_fee = 1.5;
public:
    CheckingAccount(std::string name = def_name, double balance = def_balance);
    // Inherited deposit
    bool withdraw(double amount);
};

#endif // _CHECKINGACCOUNT_H_
</code>```

CheckingAccount.cpp:

```<code>#include "CheckingAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

CheckingAccount::CheckingAccount(std::string name, double balance)
    : Account(name, balance) {}

bool CheckingAccount::withdraw(double amount) {
    amount += def_fee;
    return Account::withdraw(amount);
}

std::ostream& operator<<(std::ostream& out, const CheckingAccount& account) {
    out << "[CheckingAccount: " << account.name << ": " << account.balance << ", " << account.def_fee << " withdrawal fee]";
    return out;
}
</code>```

TrustAccount.h:

```<code>#ifndef _TRUSTACCOUNT_H_
#define _TRUSTACCOUNT_H_
#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

class TrustAccount : public SavingsAccount {
    friend std::ostream& operator<< (std::ostream& out, const TrustAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_interest = 0.0;
    static constexpr double def_bonus = 50.0;
    static constexpr double def_minimum = 0.2;
protected:
    int limit;
public:
    TrustAccount(std::string name = def_name, double balance = def_balance, double interest = def_interest, int limit = 0);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _TRUSTACCOUNT_H_
</code>```

TrustAccount.cpp:

```<code>#include "TrustAccount.h"
#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

TrustAccount::TrustAccount(std::string name, double balance, double interest, int limit)
    : SavingsAccount(name, balance, interest), limit{ 0 } {}

bool TrustAccount::deposit(double amount) {
    if (!SavingsAccount::deposit(amount))
        return false;
    if (amount >= 5000)
        Account::deposit(def_bonus);
    return true;
}

bool TrustAccount::withdraw(double amount) {
    if ((limit >= 3) || (amount > (balance * def_minimum)))
        return false;
    limit++;
    return SavingsAccount::withdraw(amount);
}

std::ostream& operator<<(std::ostream& out, const TrustAccount& account) {
    out << "[TrustAccount: " << account.name << ": " << account.balance << ", " << account.interest << "%, " << account.def_bonus << " deposit bonus, " << (3 - account.limit) << " withdrawals remaining]";
    return out;
}
</code>```

Acctools is the part I use to facilitate displaying the code and testing it out. It just takes a vector of Account (and its derivatives) objects and mass-deposits/mass-withdraws/displays-all.

Acctools.h:

```<code>#ifndef _ACCTOOLS_H_
#define _ACCTOOLS_H_
#include <vector>
#include <string>
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

// Accounts

void display(const std::vector<Account>& accounts);
void deposit(const std::vector<Account>& accounts, double balance);
void withdraw(const std::vector<Account>& accounts, double balance);

// SavingsAccounts

void display(const std::vector<SavingsAccount>& accounts);
void deposit(const std::vector<SavingsAccount>& accounts, double balance);
void withdraw(const std::vector<SavingsAccount>& accounts, double balance);

// CheckingAccounts

void display(const std::vector<CheckingAccount>& accounts);
void deposit(const std::vector<CheckingAccount>& accounts, double balance);
void withdraw(const std::vector<CheckingAccount>& accounts, double balance);

// TrustAccounts

void display(const std::vector<TrustAccount>& accounts);
void deposit(const std::vector<TrustAccount>& accounts, double balance);
void withdraw(const std::vector<TrustAccount>& accounts, double balance);

#endif // _ACCTOOLS_H_
</code>```

Acctools.cpp:

```<code>#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
#include <iostream>

class Account {
    friend std::ostream& operator<< (std::ostream &out, const Account& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
protected:
    std::string name;
    double balance;
public:
    Account(std::string name = def_name, double balance = def_balance);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _ACCOUNT_H_
</code>```0

Finally, the main:

```<code>#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
#include <iostream>

class Account {
    friend std::ostream& operator<< (std::ostream &out, const Account& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
protected:
    std::string name;
    double balance;
public:
    Account(std::string name = def_name, double balance = def_balance);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _ACCOUNT_H_
</code>```1

Post answer edit:

Here's the better TrustAccount initialization:

```<code>#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
#include <iostream>

class Account {
    friend std::ostream& operator<< (std::ostream &out, const Account& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
protected:
    std::string name;
    double balance;
public:
    Account(std::string name = def_name, double balance = def_balance);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _ACCOUNT_H_
</code>```2

答:
Your declarations of the deposit and withdraw overloads in Acctools.h have const on the std::vector of the account type.

The fix is to remove const so that the declarations matches the definitions in Acctools.cpp:

```<code>#ifndef _ACCTOOLS_H_
#define _ACCTOOLS_H_
#include <vector>
#include <string>
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

// Accounts

void display(const std::vector<Account>& accounts);
void deposit(std::vector<Account>& accounts, double balance);
void withdraw(std::vector<Account>& accounts, double balance);

// SavingsAccounts

void display(const std::vector<SavingsAccount>& accounts);
void deposit(std::vector<SavingsAccount>& accounts, double balance);
void withdraw(std::vector<SavingsAccount>& accounts, double balance);

// CheckingAccounts

void display(const std::vector<CheckingAccount>& accounts);
void deposit(std::vector<CheckingAccount>& accounts, double balance);
void withdraw(std::vector<CheckingAccount>& accounts, double balance);

// TrustAccounts

void display(const std::vector<TrustAccount>& accounts);
void deposit(std::vector<TrustAccount>& accounts, double balance);
void withdraw(std::vector<TrustAccount>& accounts, double balance);

#endif // _ACCTOOLS_H_
</code>```

Body:
Okay, so I'm currently a beginner programmer for C++ (year 11 in school, 3rd year of high school but we're still studying basic functions, so please excuse any rookie mistakes) and I'm learning additional coding knowledge by myself. Context aside, I moved to Visual Studio 2022 and I'm following a course, currently learning about Inheritance.

Thing is, I have a project with a base Account class and 3 other publicly derived classes (from the Account class) and each of these have headers and definition files, but whenever I try to run the main I get the following error chain:

1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > const &,double)" (?deposit@@YAXAEBV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > const &,double)" (?withdraw@@YAXAEBV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > const &,double)" (?deposit@@YAXAEBV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl deposit(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?deposit@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl deposit(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?deposit@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::deposit(double)" (?deposit@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl SavingsAccount::deposit(double)" (?deposit@SavingsAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::deposit(double)" (?deposit@TrustAccount@@QEAA_NN@Z)
1>SectionChallenge.obj : error LNK2019: unresolved external symbol "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > const &,double)" (?withdraw@@YAXAEBV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z) referenced in function main
1>  Hint on symbols that are defined and could potentially match:
1>    "void __cdecl withdraw(class std::vector<class Account,class std::allocator<class Account> > &,double)" (?withdraw@@YAXAEAV?$vector@VAccount@@V?$allocator@VAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class CheckingAccount,class std::allocator<class CheckingAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VCheckingAccount@@V?$allocator@VCheckingAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class SavingsAccount,class std::allocator<class SavingsAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VSavingsAccount@@V?$allocator@VSavingsAccount@@@std@@@std@@N@Z)
1>    "void __cdecl withdraw(class std::vector<class TrustAccount,class std::allocator<class TrustAccount> > &,double)" (?withdraw@@YAXAEAV?$vector@VTrustAccount@@V?$allocator@VTrustAccount@@@std@@@std@@N@Z)
1>    "public: bool __cdecl Account::withdraw(double)" (?withdraw@Account@@QEAA_NN@Z)
1>    "public: bool __cdecl CheckingAccount::withdraw(double)" (?withdraw@CheckingAccount@@QEAA_NN@Z)
1>    "public: bool __cdecl TrustAccount::withdraw(double)" (?withdraw@TrustAccount@@QEAA_NN@Z)
1>C:\Users\Sapok\Desktop\Programming_projects\Visual Studio\ConstructorsAndDestructors\x64\Debug\3. Inheritance - DerivingClasses.exe : fatal error LNK1120: 8 unresolved externals

From what I've gathered, the compiler is either pissed that it hasn't found any definitions for the functions I declared in the headers, or it's pissed that it can't tell apart between the "deposit" and "withdraw" functions for each class (each class has those 2 methods and they're named the same everywhere, but inheritance should make it work fine, I've checked the code itself and no other compiler errors appear). At this point, I'm genuinely stumped as to what the hell the compiler's crying about and how to fix it.

I've tried to include all the headers in all the files, all the .cpp files everywhere. Including the .cpp files only makes it spit out the LNK1169 (multiply defined symbols) instead, so no bueno. I've tried copying everything to a fresh solution and to no avail, I've double and triple checked all the code, I've tried moving files around, I've scoured a number of posts talking about this same type of error and none of them seem to help.

(A screenshot of my project's file distribution):
https://i.stack.imgur.com/gOXym.png

For example's sake, here's my base Account class header...

#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
#include <iostream>

class Account {
    friend std::ostream& operator<< (std::ostream &out, const Account& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
protected:
    std::string name;
    double balance;
public:
    Account(std::string name = def_name, double balance = def_balance);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _ACCOUNT_H_

...and its definition .cpp file.

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

Account::Account(std::string name, double balance)
    : name{ name }, balance{ balance } {}

bool Account::deposit(double amount) {
    if (amount < 0)
        return false;
    else {
        balance += amount;
        return true;
    }
}

bool Account::withdraw(double amount) {
    if (balance - amount < 0)
        return false;
    else {
        balance -= amount;
        return true;
    }
}

std::ostream& operator<<(std::ostream& out, const Account& account) {
    out << "[Account: " << account.name << ": " << account.balance << "]";
    return out;
}

All the other classes are very similar, as inheritance usually works.

Sorry for the long-winded explanation, I'm still new to all this and I just wanna make sure I get all the necessary details across. If anyone has any general etiquette tips for help posts like this one, that'd be greatly appreciated as well :)

Thanks in advance!

Edit: I'll include all the code - I think this isn't clear enough.

Account.h and Account.cpp are included above

SavingsAccount.h:

#ifndef _SAVINGSACCOUNT_H_
#define _SAVINGSACCOUNT_H_
#include "Account.h"
#include <string>
#include <iostream>

class SavingsAccount : public Account{
    friend std::ostream& operator<< (std::ostream& out, const SavingsAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_interest = 0.0;
protected:
    double interest;
public:
    SavingsAccount(std::string name = def_name, double balance = def_balance, double interest = def_interest);
    bool deposit(double amount);
    // Inherited withdraw
};

#endif // _SAVINGSACCOUNT_H_

SavingsAccount.cpp:

#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

SavingsAccount::SavingsAccount(std::string name, double balance, double interest)
    : Account(name, balance), interest{ interest } {}

bool SavingsAccount::deposit(double amount) {
    amount += amount * (interest / 100);
    return Account::deposit(amount);
}

std::ostream& operator<<(std::ostream& out, const SavingsAccount& account) {
    out << "[SavingsAccount: " << account.name << ": " << account.balance << ", " << account.interest << "%]";
    return out;
}

CheckingAccount.h:

#ifndef _CHECKINGACCOUNT_H_
#define _CHECKINGACCOUNT_H_
#include "Account.h"
#include <string>
#include <iostream>

class CheckingAccount : public Account {
    friend std::ostream& operator<< (std::ostream& out, const CheckingAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_fee = 1.5;
public:
    CheckingAccount(std::string name = def_name, double balance = def_balance);
    // Inherited deposit
    bool withdraw(double amount);
};

#endif // _CHECKINGACCOUNT_H_

CheckingAccount.cpp:

#include "CheckingAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

CheckingAccount::CheckingAccount(std::string name, double balance)
    : Account(name, balance) {}

bool CheckingAccount::withdraw(double amount) {
    amount += def_fee;
    return Account::withdraw(amount);
}

std::ostream& operator<<(std::ostream& out, const CheckingAccount& account) {
    out << "[CheckingAccount: " << account.name << ": " << account.balance << ", " << account.def_fee << " withdrawal fee]";
    return out;
}

TrustAccount.h:

#ifndef _TRUSTACCOUNT_H_
#define _TRUSTACCOUNT_H_
#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

class TrustAccount : public SavingsAccount {
    friend std::ostream& operator<< (std::ostream& out, const TrustAccount& account);
private:
    static constexpr const char* def_name = "Unnamed account";
    static constexpr double def_balance = 0.0;
    static constexpr double def_interest = 0.0;
    static constexpr double def_bonus = 50.0;
    static constexpr double def_minimum = 0.2;
protected:
    int limit;
public:
    TrustAccount(std::string name = def_name, double balance = def_balance, double interest = def_interest, int limit = 0);
    bool deposit(double amount);
    bool withdraw(double amount);
};

#endif // _TRUSTACCOUNT_H_

TrustAccount.cpp:

#include "TrustAccount.h"
#include "SavingsAccount.h"
#include "Account.h"
#include <string>
#include <iostream>

TrustAccount::TrustAccount(std::string name, double balance, double interest, int limit)
    : SavingsAccount(name, balance, interest), limit{ 0 } {}

bool TrustAccount::deposit(double amount) {
    if (!SavingsAccount::deposit(amount))
        return false;
    if (amount >= 5000)
        Account::deposit(def_bonus);
    return true;
}

bool TrustAccount::withdraw(double amount) {
    if ((limit >= 3) || (amount > (balance * def_minimum)))
        return false;
    limit++;
    return SavingsAccount::withdraw(amount);
}

std::ostream& operator<<(std::ostream& out, const TrustAccount& account) {
    out << "[TrustAccount: " << account.name << ": " << account.balance << ", " << account.interest << "%, " << account.def_bonus << " deposit bonus, " << (3 - account.limit) << " withdrawals remaining]";
    return out;
}

Acctools is the part I use to facilitate displaying the code and testing it out. It just takes a vector of Account (and its derivatives) objects and mass-deposits/mass-withdraws/displays-all.

Acctools.h:

#ifndef _ACCTOOLS_H_
#define _ACCTOOLS_H_
#include <vector>
#include <string>
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

// Accounts

void display(const std::vector<Account>& accounts);
void deposit(const std::vector<Account>& accounts, double balance);
void withdraw(const std::vector<Account>& accounts, double balance);

// SavingsAccounts

void display(const std::vector<SavingsAccount>& accounts);
void deposit(const std::vector<SavingsAccount>& accounts, double balance);
void withdraw(const std::vector<SavingsAccount>& accounts, double balance);

// CheckingAccounts

void display(const std::vector<CheckingAccount>& accounts);
void deposit(const std::vector<CheckingAccount>& accounts, double balance);
void withdraw(const std::vector<CheckingAccount>& accounts, double balance);

// TrustAccounts

void display(const std::vector<TrustAccount>& accounts);
void deposit(const std::vector<TrustAccount>& accounts, double balance);
void withdraw(const std::vector<TrustAccount>& accounts, double balance);

#endif // _ACCTOOLS_H_

Acctools.cpp:

#include "Acctools.h"
#include <vector>
#include <string>
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

// Accounts
void display(const std::vector<Account>& accounts) {
    std::cout << "\n===Accounts========================================" << '\n';
    for (const auto& acc : accounts)
        std::cout << acc << '\n';
}

void deposit(std::vector<Account>& accounts, double amount) {
    std::cout << "\n===Depositing to Accounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.deposit(amount))
            std::cout << "Deposited " << amount << " to " << acc << '\n';
        else
            std::cout << "Failed deposit of  " << amount << " to " << acc << '\n';
}

void withdraw(std::vector<Account>& accounts, double amount) {
    std::cout << "\n===Withdrawing from Accounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.withdraw(amount))
            std::cout << "Withdrawn " << amount << " from " << acc << '\n';
        else
            std::cout << "Failed withdrawal of " << amount << " from " << acc << '\n';
}

// Savings Accounts

void display(const std::vector<SavingsAccount>& accounts) {
    std::cout << "\n===SavingsAccounts========================================" << '\n';
    for (const auto& acc : accounts)
        std::cout << acc << '\n';
}

void deposit(std::vector<SavingsAccount>& accounts, double amount) {
    std::cout << "\n===Depositing to SavingsAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.deposit(amount))
            std::cout << "Deposited " << amount << " to " << acc << '\n';
        else
            std::cout << "Failed deposit of  " << amount << " to " << acc << '\n';
}

void withdraw(std::vector<SavingsAccount>& accounts, double amount) {
    std::cout << "\n===Withdrawing from SavingsAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.withdraw(amount))
            std::cout << "Withdrawn " << amount << " from " << acc << '\n';
        else
            std::cout << "Failed withdrawal of " << amount << " from " << acc << '\n';
}

// Checking Accounts

void display(const std::vector<CheckingAccount>& accounts) {
    std::cout << "\n===CheckingAccounts========================================" << '\n';
    for (const auto& acc : accounts)
        std::cout << acc << '\n';
}

void deposit(std::vector<CheckingAccount>& accounts, double amount) {
    std::cout << "\n===Depositing to CheckingAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.deposit(amount))
            std::cout << "Deposited " << amount << " to " << acc << '\n';
        else
            std::cout << "Failed deposit of  " << amount << " to " << acc << '\n';
}

void withdraw(std::vector<CheckingAccount>& accounts, double amount) {
    std::cout << "\n===Withdrawing from CheckingAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.withdraw(amount))
            std::cout << "Withdrawn " << amount << " from " << acc << '\n';
        else
            std::cout << "Failed withdrawal of " << amount << " from " << acc << '\n';
}

// Trust Accounts

void display(const std::vector<TrustAccount>& accounts) {
    std::cout << "\n===TrustAccounts========================================" << '\n';
    for (const auto& acc : accounts)
        std::cout << acc << '\n';
}

void deposit(std::vector<TrustAccount>& accounts, double amount) {
    std::cout << "\n===Depositing to TrustAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.deposit(amount))
            std::cout << "Deposited " << amount << " to " << acc << '\n';
        else
            std::cout << "Failed deposit of  " << amount << " to " << acc << '\n';
}

void withdraw(std::vector<TrustAccount>& accounts, double amount) {
    std::cout << "\n===Withdrawing from TrustAccounts========================================" << '\n';
    for (auto& acc : accounts)
        if (acc.withdraw(amount))
            std::cout << "Withdrawn " << amount << " from " << acc << '\n';
        else
            std::cout << "Failed withdrawal of " << amount << " from " << acc << '\n';
}

Finally, the main:

#include <iostream>
#include <string>
#include <vector>
#include "Acctools.h"
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

int main() {

    //////////////////////////////////////////////////// ACCOUNTS

    std::vector<Account> accounts;

    accounts.push_back(Account{ "Cata", 2000 });
    accounts.push_back(Account{ "Pernea", 0 });
    accounts.push_back(Account{ "Razvi", 4000 });

    display(accounts);

    deposit(accounts, 1000);

    display(accounts);

    withdraw(accounts, 3000);

    display(accounts);

    //////////////////////////////////////////////////// SAVINGS ACCOUNTS

    std::vector<SavingsAccount> savingsaccounts;

    savingsaccounts.push_back(SavingsAccount{ "Sapokee", 2000, 5.0 });
    savingsaccounts.push_back(SavingsAccount{ "Bernea", 0, 200.0 });
    savingsaccounts.push_back(SavingsAccount{ "Ravi", 4000, 1.0 });

    display(savingsaccounts);

    deposit(savingsaccounts, 1000);

    display(savingsaccounts);

    withdraw(savingsaccounts, 3000);

    display(savingsaccounts);

    //////////////////////////////////////////////////// CHECKING ACCOUNTS

    std::vector<CheckingAccount> checkingaccounts;

    checkingaccounts.push_back(CheckingAccount{ "Sapok", 2000 });
    checkingaccounts.push_back(CheckingAccount{ "Alex Bernea", 0 });
    checkingaccounts.push_back(CheckingAccount{ "Ravioli", 4000});

    display(checkingaccounts);

    deposit(checkingaccounts, 1000);

    display(checkingaccounts);

    withdraw(checkingaccounts, 3000);

    display(checkingaccounts);

    //////////////////////////////////////////////////// TRUST ACCOUNTS

    std::vector<TrustAccount> trustaccounts;

    trustaccounts.push_back(TrustAccount{ "Sapokee", 2000, 5.0 });
    trustaccounts.push_back(TrustAccount{ "Bernea", 0, 1.0 });
    trustaccounts.push_back(TrustAccount{ "Ravi", 4000, 1.0 });

    display(trustaccounts);

    deposit(trustaccounts, 5000);

    display(trustaccounts);

    withdraw(trustaccounts, 3000);

    display(trustaccounts);

    withdraw(trustaccounts, 100);

    display(trustaccounts);

    withdraw(trustaccounts, 100);

    display(trustaccounts);

    withdraw(trustaccounts, 100);

    display(trustaccounts);

    withdraw(trustaccounts, 100);

    display(trustaccounts);
}

Post answer edit:

Here's the better TrustAccount initialization:

private:
    // ... all other default values
    static constexpr int def_withdrawals = 0;
protected:
    int withdrawals; // changed the name to be more intuitive
public:
    TrustAccount(std::string name = def_name, double balance = def_balance, double interest = def_interest); // removed withdrawals from here

TrustAccount::TrustAccount(std::string name, double balance, double interest)
    : SavingsAccount(name, balance, interest), withdrawals{ def_withdrawals } {}

Body:
Your declarations of the deposit and withdraw overloads in Acctools.h have const on the std::vector of the account type.

The fix is to remove const so that the declarations matches the definitions in Acctools.cpp:

#ifndef _ACCTOOLS_H_
#define _ACCTOOLS_H_
#include <vector>
#include <string>
#include <iostream>
#include "Account.h"
#include "SavingsAccount.h"
#include "CheckingAccount.h"
#include "TrustAccount.h"

// Accounts

void display(const std::vector<Account>& accounts);
void deposit(std::vector<Account>& accounts, double balance);
void withdraw(std::vector<Account>& accounts, double balance);

// SavingsAccounts

void display(const std::vector<SavingsAccount>& accounts);
void deposit(std::vector<SavingsAccount>& accounts, double balance);
void withdraw(std::vector<SavingsAccount>& accounts, double balance);

// CheckingAccounts

void display(const std::vector<CheckingAccount>& accounts);
void deposit(std::vector<CheckingAccount>& accounts, double balance);
void withdraw(std::vector<CheckingAccount>& accounts, double balance);

// TrustAccounts

void display(const std::vector<TrustAccount>& accounts);
void deposit(std::vector<TrustAccount>& accounts, double balance);
void withdraw(std::vector<TrustAccount>& accounts, double balance);

#endif // _ACCTOOLS_H_


问:
SNOWFLAKE- Trying to run task on 2nd Tuesday of every month (USING CRON 0 15 8-14 * 2 UTC)- running for all days 8-14? Why?
I am trying to run the Snowflake task on the 2nd Tuesday of every month using (USING CRON 0 15 8-14 * 2 UTC). But it is running for all the days between 8-14. Why this behavior? Is this a known issue in snowflake?</p>

答:
there are plenty of online cron generators that will create cron strings for you.

This string should do what you want:

0 0 15 ? 1/1 TUE#2 *