Why the code cannot be compiled?


C

ccs

The compile error is: error C2059: syntax error : 'constant'.

Since CEngine does have a constructor taking three parameters.

class CEngine
{
public:
CEngine(int a, int b, int c) {}
};

class CCar
{
CEngine e(1,2,3);
....
};

Thanks in advance!
 
Ad

Advertisements

P

Pete C.

ccs said:
The compile error is: error C2059: syntax error : 'constant'.

Since CEngine does have a constructor taking three parameters.

class CEngine
{
public:
CEngine(int a, int b, int c) {}
};

class CCar
{
CEngine e(1,2,3);
...
};

Thanks in advance!

class Car
{
Engine e;
Car() : e(1, 2, 3) {}
};

- Pete
 
Ad

Advertisements

D

David Harmon

class Car
{
Engine e;
Car() : e(1, 2, 3) {}
};

Except that the class was named "CEngine". But I would like to
suggest, avoid naming classes with the initial capital C, since
Microsoft has adopted that prefix for many of theirs (since the days
before "namespace" was available) and it is most useful to name your
classes in such a way that they are easily distinguishable from others.
So "Engine" it may be after all.
 

Top