Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

extern declare in a template

15 views
Skip to first unread message

Joe

unread,
Jun 8, 2015, 10:26:23 PM6/8/15
to
I've got a header that extern declares a var which is defined within a
globals.cpp. I do this for very few globals.


--- globals.h
#pragma once

extern MyGlobalClass my_gclass;


--- globals.cpp

MyGlobalClass my_gclass;


--- aclass.h
#include "globals.h"

template <class SomeClass>
class AnotherClass
{
// ...

void operator()() {

my_gclass->func(...);

}

};


The problem is that it won't compile.

aclass.h:102:29: error: 'my_gclass' was not declared in this scope
error = my_gclass->func(...

I don't understand that since the #include "globals.h" is in aclass.h.

However, if I add "extern MyGlobalClass my_gclass;" just after #include
"globals.h in the aclass.h template file, it works.

Can someone explain this?




Paavo Helde

unread,
Jun 9, 2015, 12:50:55 AM6/9/15
to
Joe <no....@noemail.com> wrote in news:ml5ir...@news3.newsguy.com:
Probably some confusion with namespaces. Or a spelling mistake, recheck
your names for silly errors like license/licence.

hth
Paavo

Barry Schwarz

unread,
Jun 9, 2015, 1:48:29 AM6/9/15
to
Instead of compiling a .h file, create a .cpp file which includes
aclass.h (along with Somme trivial function definition) and see if
that works.

--
Remove del for email
0 new messages