Mario, this is about a 2002 thread...
I'm currently compiling code on a linux box and running into namespace problems.
As I go through the permutations of namespace combinations I'm able to mimic much of the action discussed here and in other threads.
In the beginning all my classes were saying "...expected...before...token"
Then I took out the namespace std and this helped because then I was able to see THAT my classes were suffering from the same types of problems.
So, I was able to solve half the problems dealing with scope by playing with namespace, etc.
BUT, the classes are still not working.
The example below is a mix of std:: and not std:: to see what happens. I can add std:: to every call but what can make my classes work?
Thanks 10^6
Dave
PS - I'm coding this summer...this never happened in C
Will "namespaces" ultimately kill C++ ?
It's all in progress...but I've clipped the larger code down to bare bones for testing.
Thanks for the help in advance (begging by any other cleche)
Code:
cat -n Vtest.h (clipped)
4 // The routines will initially return text messages for debugging and then later be overloaded for data
5
6 #include <iostream>
7 #include <fstream>
8 #include <stdio.h>
9 #include <time.h>
10 #include <math.h>
11
12 #include <usb.h>
13 #include <libxxusb.h>
14
15 class vtest
16 {
17 private:
18 usb_dev_handle *udev; // Device Handle
19 char scalerChar[20];
20 long value;
21 public:
22 int icount;
23 vtest(usb_dev_handle *udev);
24 void vtestvoid(long &value);
25 long vtestlong(long &value);
26 char vtestchar(long &value);
27 int vtestcount(int icount);
28 int vtestvalue(void);
29 };
30
31 vtest::vtest(usb_dev_handle *udev){
32 icount = 0;
33 value = 90:
34 }
35
36 vtest::vtestvoid(&value){
37 value = 98;
38 }
39
40 vtest::vtestlong(&value){
41 value = 99;
42 return(value);
43 }
cat -n Vtest.cpp (clipped)
5 #include <iostream>
6 #include <fstream>
7 #include "Vtest.h" // case sensetive
8
9 std::cout cout;
10 std::endl endl;
11
12 int CheckDevice(usb_dev_handle *udev){ //Check if device is open. If not, end program
13 if(udev)
14 {
15 cout << "VM-USB device is open for communication" << endl;
16 }
17 else
18 {
19 cout << "No VM-USB devices found!" << endl;
20 // fout << "No VM-USB devices found!" << endl; // send a message to the log file?
21 return 0; // won't end the program but useful to if()
22 }
23 }
24
25 int main ()
26 {
27 // initialize
28 char logName[79];
29 long value;
30
31 xxusb_device_type devices[99];
32 struct usb_device *dev;
33 usb_dev_handle *udev; // Device Handle
34
35 //Find XX_USB devices and open the first one found
36 xxusb_devices_find(devices);
37 dev = devices[0].usbdev;
38 udev = xxusb_device_open(dev);
39
40 std::cout << "Trying to establish communication with the VM-USB" << std::endl;
41
42 if (!CheckDevice(udev)) return 0;
In file included from Vtest.cpp:7:
Vtest.h: In constructor `vtest::vtest(usb_dev_handle*)':
Vtest.h:33: error: expected `;' before ':' token
Vtest.h: At global scope:
Vtest.h:36: error: expected constructor, destructor, or type conversion before '(' token
Vtest.h:36: error: expected `,' or `;' before '(' token
Vtest.h:40: error: expected constructor, destructor, or type conversion before '(' token
Vtest.h:40: error: expected `,' or `;' before '(' token
Vtest.h:45: error: expected constructor, destructor, or type conversion before '(' token
Vtest.h:45: error: expected `,' or `;' before '(' token
Vtest.h:51: error: expected constructor, destructor, or type conversion before '(' token
Vtest.h:51: error: expected `,' or `;' before '(' token
Vtest.h:56: error: ISO C++ forbids declaration of `vtestvalue' with no type
Vtest.cpp:9: error: expected constructor, destructor, or type conversion before "cout"
Vtest.cpp:9: error: expected `,' or `;' before "cout"
Vtest.cpp:10: error: expected constructor, destructor, or type conversion before "endl"
Vtest.cpp:10: error: expected `,' or `;' before "endl"
Vtest.cpp: In function `int CheckDevice(usb_dev_handle*)':
Vtest.cpp:15: error: `cout' undeclared (first use this function)
Vtest.cpp:15: error: (Each undeclared identifier is reported only once for each function it appears in.)
Vtest.cpp:15: error: `endl' undeclared (first use this function)
make: *** [Vtest] Error 1
Makefile (clipped)
3 .LIBPATTERNS ="'lib%.so lib%.a' "
4
5 VERBOSE = 1
6
7 CXX = g++ -v -g
8
9 RM = rm *~
10
11 LD = gcc-3.3
12 LDFLAGS = -O
13 SOFLAGS = -shared
14
15 CXXLIBDIRS = -l /usr/include/lib/
16 CXXLIBS = -l xx_usb
17 INCLUDEDIRS = -I .
18
19 CXXFLAGS = -O -Wall -fPIC -g $(INCLUDEDIRS)
20
21 LDFLAGS = $(CXXFLAGS)
22
23 OBJ = Vtest.exe
24
25 Vtest:
26 $(CXX) $(CXXFLAGS) \
27 $(CXXLIBS) $(CXXLIBDIRS) -o $(OBJ) Vtest.cpp
28 @echo "Done"