Category Archives: StackOverFlow

Stack Overflow is a question and answer site for professional and enthusiast programmers.

Two variables in seperate translation units are violating the one definition rule?

I have a variable const char * FILENAME = "a/file/name" defined in two .cpp files, called a.cpp and b.cpp. Nothing includes these files directly, and they only include a.h and b.h respectively into themselves. Both of those header files are then included in main.cpp

My problem is that I’m getting the following linker error:

a.obj : error LNK2005: "char const * const FILENAME" (?FILENAME@@3PBDB) already defined in b.obj

I don’t use file scope variables very often, so I thought this would be okay… What am I doing wrong here?

read more

Search only on alphanumeric chars of a column

I have a table column of type nvarchar.
As an example, lets say one of the records is A320 - Airbus.
Contains both alphanumerics and a hyphen in this case.

When I search for 320A, the search should pick it up by ignoring the 2 whitespaces and a hyphen between the 2 words.

Currently, I can achieve this by doing this

SELECT DISTINCT Name 
FROM Entity
WHERE REPLACE(REPLACE(Name, ' ', ''), '-', '') LIKE '%320A%'; 

But if I have to add more escape chars, I have to keep applying REPLACE for every new escape char.

read more

Initializing array in cpp and padding with zeros

I’m new a c++, switched from matlab to run simulations faster.
quick question:
I want to initialize an array and have it padded with zeros.
I have:

    # include <iostream>
# include <string>
# include <cmath>

using namespace std;


int main()
{
    int nSteps = 10000;
    int nReal = 10;
    double H[nSteps*nReal];
    return 0;

}

It produces an error:

expected constant expression

cannot allocate an array of constant size 0

‘H’ : unknown size

??????? how do u do this simple thing, also is there a library with a command

read more

Initializing array in cpp and padding with zeros

I’m new a c++, switched from matlab to run simulations faster.
quick question:
I want to initialize an array and have it padded with zeros.
I have:

    # include <iostream>
# include <string>
# include <cmath>

using namespace std;


int main()
{
    int nSteps = 10000;
    int nReal = 10;
    double H[nSteps*nReal];
    return 0;

}

It produces an error:

expected constant expression

cannot allocate an array of constant size 0

‘H’ : unknown size

??????? how do u do this simple thing, also is there a library with a command

read more