Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7958877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:29:14+00:00 2026-06-04T04:29:14+00:00

I am working on a project in C++ which has many functions. I don’t

  • 0

I am working on a project in C++ which has many functions. I don’t want to write them in the main program and would like to write a separate .cpp file for each of the functions. Most of these functions will act on some arrays, so I wish to make these arrays global. So I declared all the arrays in a separate .cpp file called globals.cpp and put them in a globals.h file prefixed with extern. The I wrote the functions and the main program as usual, however when I compile, I get an

Here is what I have:

//globals.cpp

#include <iostream>
#include <blitz/blitz.h>
#include <blitz/array.h>
#include "prototype.h"
#include "globals.h"

BZ_USING_NAMESPACE(blitz)

Array<double,2> A(5,5);

In the globals.h file I have

#ifndef GLOBALS_H
#define GLOBALS_H
extern Array<double,2> A(5,5);
#endif

Then I have a function add.cpp, for example

#include <iostream>
#include <blitz/blitz.h>
#include <blitz/array.h>
#include "prototype.h"
#include "globals.h"

BZ_USING_NAMESPACE(blitz)

void add.cpp(){
   for(int i=0;i<5;i++){
      A(i,i)=i*i;
   }
}

I obviously include it in the prototype.h file

#ifndef GLOBALS_H
#define GLOBALS_H
void add();
#endif

Finally I have the main program mainprog.c

#include <iostream>
#include <blitz/blitz.h>
#include <blitz/array.h>
#include "prototype.h"
#include "globals.h"

BZ_USING_NAMESPACE(blitz)
int main(){
   add();
   cout<<A<<endl;
   return 0;
}

However when I compile I get the error `globals.h:6:8: error: ‘Array’ does not name a type

and then an error in the add.cpp function saying the error A was not declared.

How do I declare the blitz arrays as global?
Thank you
`

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:29:15+00:00Added an answer on June 4, 2026 at 4:29 am

    The issue is that your macro to import the namespace(BZ_USING_NAMESPACE) is below your include of globals.h. Thus the Array class you are trying to reference in globals.h is actually blitz::Array or something at that point.

    For a simple fix, simply use the BZ_USING_NAMESPACE in globals.h right above your declaration for A.

    Always remember to include everything a header file needs in that header file.

    #ifndef GLOBALS_H
    #define GLOBALS_H
    
    #include <blitz/blitz.h> //No idea if the Array class needs this header.
    #include <blitz/array.h>
    BZ_USING_NAMESPACE(blitz)
    
    extern Array<double,2> A(5,5);
    #endif
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working for a project which has many XSLT transformations. The transformations have
I've a project that I'm working on which has not been started by me.
I've just finished working for a client which has burnt millions on a project
I am currently working on a MYSQL project which has a few fairly standard
The project I'm working on has a need to represent many different hardware registers
I am working on a project which has no determined algorithm to solve using
I'm working with an external framework (redmine) which has one Project model that has_many
I'm working on a big Java project which has been around for a while
I'm working on a large program which has an abstracted GUI API. It is
I'm currently working on a project which uses many ajax requests to access data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.