Class errors

This is a discussion on Class errors within the C++ Programming forums, part of the General Programming Boards category; I am getting errors like 'copyStr' was not declared in this scope. To explain easier, I have what I'll call ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    7

    Class errors

    I am getting errors like 'copyStr' was not declared in this scope.

    To explain easier, I have what I'll call class a and class b. Both are in separate .cpp files. I am attempting to call a method from class b whilst in a method in class a that uses class b as a parameter. I will then get the error above.

  2. #2
    Registered User
    Join Date
    Jun 2005
    Posts
    6,646
    The class a method needs to have visibility of the definition of class b. A forward declaration is not enough.

    That is usually done by having a.cpp do an #include "b.h" where b.h declares class b (and its member functions). This #include must occur before the code that tries to call a member of class b.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Sunshine, and read this, this, and this before posting again.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Stuck with function
    By scmurphy64 in forum C Programming
    Replies: 9
    Last Post: 11-10-2009, 11:41 AM
  2. Replies: 8
    Last Post: 10-02-2005, 01:27 AM
  3. Class Errors (LNK2005)
    By NMZ in forum C++ Programming
    Replies: 4
    Last Post: 02-28-2005, 03:52 PM
  4. errors in my class....
    By o0obruceleeo0o in forum C++ Programming
    Replies: 9
    Last Post: 04-14-2003, 04:22 AM
  5. Warnings, warnings, warnings?
    By spentdome in forum C Programming
    Replies: 25
    Last Post: 05-27-2002, 07:49 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21