In this complete code:
class foo
{
public:
foo(const int pin);
};
class bar {
public:
// Constructor
bar(const int dataPin) : dataPin_ (dataPin) { }
private:
const int dataPin_;
foo myFoo_ (dataPin_); // instance of foo
};
int main (void)
{
return 0;
}
Using g++ 4.8.4 I get the error:
g++ -Wall -c "test.cpp" (in directory: /home/nick/Development)
test.cpp:14:17: error: ‘dataPin_’ is not a type
foo myFoo_ (dataPin_); // instance of foo
^
Compilation failed.
Using clang 3.4-1ubuntu3 I get:
test.cpp:14:17: error: unknown type name 'dataPin_'
foo myFoo_ (dataPin_); // instance of foo
^
1 error generated.
Why does it want a type here? This is attempting to create an instance of foo
as a class variable of bar
. The variable dataPin_
is declared directly above.
If I change the line with the error to this, it compiles cleanly:
foo myFoo_ (int dataPin_); // instance of foo