473,406 Members | 2,369 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

error: ISO C++ forbids declaration of 'm' with no type

I suspect I don't understand namespaces or something, but does anyone have an idea of why the following code segment which is all in a single *.h file causes a compile error?

namespace first {
typedef class _A {
public:
_A() {};
~_A() {};
void set(int c) {b = c;};
int b;
} A;
} //end namespace first

namespace first {
namespace second {
namespace third {
class foo {
public:
foo() {};
~foo() {};
int c;
A m;
m.set(c);
};
} // end third
} //end second
} // end first

Any help or debug ideas appreciated. Thanks
Mar 1 '08 #1
3 2032
weaknessforcats
9,208 Expert Mod 8TB
Several things look funny but this is an error:

m.set(c);
That is a function call inside a class definition. You can't do that.
Mar 1 '08 #2
Oh, of course you are right about that. I'll need to find another way to do this because when I originally tried writing the class _A so the constructor took an int as an argument the compiler didn't like that either:

class foo {
foo() {};
~foo() {};

A m(c);

}
Mar 2 '08 #3
weaknessforcats
9,208 Expert Mod 8TB
Really?

Expand|Select|Wrap|Line Numbers
  1. class _A
  2. {
  3.     public:
  4.        _A(int);
  5. };
  6.  
but that requires:
Expand|Select|Wrap|Line Numbers
  1. class foo
  2.  {
  3.      public:
  4.         foo(int arg) : m(arg){};
  5.        ~foo() {};
  6.      private:
  7.        A m;
  8. };
  9.  
Did you try this?
Mar 3 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Zach | last post by:
Using Dev-C++ 4.9.8.5 I get error: Compiler: Default compiler Executing g++.exe... g++.exe "C:\winroot\src\c++\stupid_tricks\functor_trick.cpp" -o...
4
by: James | last post by:
Can someone please help me with these errors? #include <iostream> #include <string> class holder { private: int vid; string vtype;
10
by: .J.T. | last post by:
Hello all, I have a strange error when try to use map<int, string> (using gcc version 2.95.2). I have this code in header file (display_map.h): #ifndef DISPLAY_MAP_H #define DISPLAY_MAP_H ...
2
by: David Williams | last post by:
Hi all, I get errors when compiling the .cpp file below, both on Visual Studio and G++. 01: //------------------------------------------------- 02: template <typename Type> 03: class Outer 04:...
4
by: rach | last post by:
I just started to learn C++. I copied the following code from a data structure textbook to a ".h" file and couldn't compile it. The code contains three template interfaces. One inherits another. The...
7
by: i | last post by:
#include<stdio.h> #include<conio.h> #include<process.h> #include<string.h> char ch; int w; int n,m; //void main(); char check(int n,int m,char ch); void cash(int n,int m,char ch);
1
by: Prosdo | last post by:
Okay, I am writing this program for class and it kind of works. It goes through the motions, but would skip the prompt where I ask if they want to add another customer. So, I realized I missed a...
6
by: wong_powah | last post by:
How to fix this compile error? # make -f Util/UtilBlock.dep g++ /opt/aCC/include_std/rw/codecvt.cc -o /opt/aCC/include_std/ rw/codecvt /opt/aCC/include_std/rw/codecvt.cc:32: error: use of...
6
by: samsneelam | last post by:
Hi.. This is samuel, while doing a program, i encountered this problem.. Let me give you clarity regarding my prob.. I am having two files .. one is mpcplib.h it contains the follwing...
3
by: Hill | last post by:
This is an simple map, just an exercise. Who can help me fix this compile issue?Thanks in advance. #include <string> #include <vector> #include <iostream> using std::vector; using std::string;...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.